我一直在使用 rest-client-builder 插件(http://grails.org/plugin/rest-client-builder)并且面临将文件作为 inputStream 对象发送的问题。
从插件文档:
通过将请求主体的属性设置为 File、URL、byte[] 或 InputStream 实例,可以实现多部分请求:
def resp = rest.post(url) {
contentType "multipart/form-data"
zip = new File(pluginPackage)
pom = new File(pomFile)
xml = new File(pluginXmlFile)
}
我的代码:
def post(String url, InputStream photo, String contentType, Cookie[] cookies = null) {
def rest = new RestBuilder()
def cookiesHeaderString = ""
if (cookies) {
cookiesHeaderString = WebUtils.buildCookiesHeader(cookies)
}
def resp = rest.post(url) {
header "Cookie", cookiesHeaderString
file = photo
contentType "multipart/form-data"
}
return resp?.responseEntity?.body
}
有人可以建议我如何发送 InputStream 对象或我做错了什么?