【问题标题】:Groovy HTTPBuilder post file upload without multipart/form-data?没有多部分/表单数据的 Groovy HTTPBuilder 发布文件上传?
【发布时间】:2014-09-29 18:51:04
【问题描述】:
如何在不使用 multipart/form-data 的情况下使用上传文件的原始字节的 HTTPBuilder 在 groovy 中执行 HTTP 发布?具体来说,我希望我的请求如下所示:
POST http://....
Host: myhost
Content-Length: numBytes
Proxy-Connection: Keep-Alive
Raw Data
【问题讨论】:
标签:
file
post
groovy
upload
httpbuilder
【解决方案1】:
你可以把它作为二进制发送
@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
}