diff --git a/CHANGELOG.md b/CHANGELOG.md index 454d61091..e27edf117 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java b/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java index fd6be1eed..c46df6120 100755 --- a/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java +++ b/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java @@ -1379,10 +1379,18 @@ public class HttpRequest extends HttpBase { * @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()); } /**