如何使用HTTPBuilder在groovy中执行HTTP帖子,该HTTPBuilder在不使用multipart / form-data的情况下上传文件的原始字节?具体来说,我希望我的请求看起来像这样:
POST http://....
Host: myhost
Content-Length: numBytes
Proxy-Connection: Keep-Alive
Raw Data
答案 0 :(得分:2)
您可以将其作为二进制文件发送
@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
}