使用multiparty方式支持body参数

This commit is contained in:
Looly
2023-07-08 18:25:43 +08:00
parent 89056a3d71
commit 2eb8f9c969
2 changed files with 14 additions and 5 deletions
+2 -1
View File
@@ -2,7 +2,7 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.21(2023-07-05)
# 5.8.21(2023-07-08)
### 🐣新特性
* 【core 】 list 为空时,CollUtil.max等返回null而非异常(pr#1027@Gitee)
@@ -12,6 +12,7 @@
* 【core 】 RandomUtil增加可选是否包含边界的重载(issue#3182@Github)
* 【core 】 StrUtil增加truncateByByteLength方法(pr#3176@Github)
* 【core 】 身份证工具类isValidCard18、isValidCard15入参null直接返回null(pr#1034@Gitee)
* 【http 】 使用multiparty方式支持body参数(issue#3158@Gitee)
### 🐞Bug修复
* 【core 】 修复MapUtil工具使用filter方法构造传入参数结果问题(issue#3162@Github)
@@ -1379,10 +1379,18 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* @throws IOException IO异常
*/
private void sendMultipart() throws IOException {
final MultipartBody multipartBody = MultipartBody.create(this.form, this.charset);
//设置表单类型为Multipart(文件上传)
this.httpConnection.header(Header.CONTENT_TYPE, multipartBody.getContentType(), true);
multipartBody.writeClose(this.httpConnection.getOutputStream());
final RequestBody body;
// issue#3158,当用户自定义为multipart同时传入body,则不做单独处理
if(null == form && null != this.body) {
body = ResourceBody.create(this.body);
}else{
final MultipartBody multipartBody = MultipartBody.create(this.form, this.charset);
//设置表单类型为Multipart(文件上传)
this.httpConnection.header(Header.CONTENT_TYPE, multipartBody.getContentType(), true);
body = multipartBody;
}
body.writeClose(this.httpConnection.getOutputStream());
}
/**