diff --git a/CHANGELOG.md b/CHANGELOG.md index f60073f78..5dd805df3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### 新特性 ### Bug修复 +* 【http】 修复HttpRquest中body方法长度计算问题(issue#I10UPG@Gitee) ------------------------------------------------------------------------------------------------------------- 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 1d27af2b0..b985a795d 100644 --- a/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java +++ b/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java @@ -630,9 +630,10 @@ public class HttpRequest extends HttpBase { * @return this */ public HttpRequest body(String body, String contentType) { - body(StrUtil.bytes(body, this.charset)); + byte[] bytes = StrUtil.bytes(body, this.charset); + body(bytes); this.form = null; // 当使用body时,停止form的使用 - contentLength((null != body ? body.length() : 0)); + contentLength(bytes.length); if (null != contentType) { // Content-Type自定义设置 @@ -675,6 +676,7 @@ public class HttpRequest extends HttpBase { * @return this */ public HttpRequest body(byte[] bodyBytes) { + Assert.notNull(bodyBytes, "Body must be not null !"); this.bodyBytes = bodyBytes; return this; } diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelWriteTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelWriteTest.java index 5b4c71001..ebc2f977a 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelWriteTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/test/ExcelWriteTest.java @@ -124,7 +124,7 @@ public class ExcelWriteTest { } @Test - @Ignore +// @Ignore public void mergeTest2() { Map row1 = new LinkedHashMap<>(); row1.put("姓名", "张三"); @@ -143,13 +143,9 @@ public class ExcelWriteTest { ArrayList> rows = CollUtil.newArrayList(row1, row2); // 通过工具类创建writer - ExcelWriter writer = ExcelUtil.getWriter("e:/writeMapTest.xlsx"); + ExcelWriter writer = ExcelUtil.getWriter("f:/test/writeMapTest.xlsx"); // 合并单元格后的标题行,使用默认标题样式 - try { - writer.merge(row1.size() - 1, "一班成绩单"); - } catch (Exception e) { - e.printStackTrace(); - } + writer.merge(row1.size() - 1, "一班成绩单"); // 一次性写出内容,使用默认样式,强制输出标题 writer.write(rows, true);