【发布时间】:2013-09-12 17:29:17
【问题描述】:
我一直在使用 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 对象或我做错了什么吗?
【问题讨论】:
-
你的代码出了什么问题?
-
contentType 出了点问题:消息:空行 |方法->> 307 | javax.activation.MimetypesFileTypeMap 中的 getContentType
标签: rest grails grails-plugin