【发布时间】:2023-03-12 15:55:02
【问题描述】:
我正在尝试使用 http builder-groovy 在服务器中上传多个文件。以下代码不起作用。出现错误“请求实体太大”。我已导入所有包并定义了所有变量。
使用 restclient-groovy 有什么替代方法吗?
谁能给出原因?
提前致谢。
def file = new File("resources/IMG.JPG")
def file1 = new File("resources/aa.json")
http = new HTTPBuilder( url )
http.request (POST, JSON) { multipartRequest ->
uri.path = '/server/upload'
uri.query = [param1:value, param2:value, param3:value, param4:value]
requestContentType = 'multipart/form-data'
MultipartEntity mpe = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE)
mpe.addPart( "jpeg", new FileBody(( File ) file , 'image/jpeg' ))
mpe.addPart( "json", new FileBody(( File ) file1 , 'application/json' ))
multipartRequest.setEntity(mpe)
response.success = { resp, json->
println "POST response status: ${resp.statusLine}"
println "Query response: ${json}"
}
response.failure = { resp ->
println "POST response statusline: ${resp.statusLine}"
}
}
【问题讨论】:
-
The below code doesn't works.到底怎么样? -
连接是否可以ping通?发布您的堆栈跟踪
-
@injecteer : POST 响应状态行:HTTP/1.1 413 请求实体太大 POST 响应状态:groovyx.net.http.HttpResponseDecorator@5c075df1
-
@sailakshmi,你有什么解决办法吗?
标签: groovy multipartform-data httpbuilder