use*_*521 4 upload groovy post file httpbuilder
如何使用 HTTPBuilder 在 groovy 中执行 HTTP post,上传文件的原始字节而不使用 multipart/form-data?具体来说,我希望我的请求如下所示:
POST http://....
Host: myhost
Content-Length: numBytes
Proxy-Connection: Keep-Alive
Raw Data
Run Code Online (Sandbox Code Playgroud)
你可以将它作为二进制发送
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
def http = new HTTPBuilder('http://localhost:8080')
http.post(path:'/', body: new File('/etc/passwd').bytes, requestContentType: BINARY) { response ->
println response.statusLine
}
Run Code Online (Sandbox Code Playgroud)