diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9c5c2f0ba..76f23c02f 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,10 +2,11 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
-# 5.8.33(2024-09-03)
+# 5.8.33(2024-09-04)
### 🐣新特性
* 【core 】 SyncFinisher增加setExecutorService方法(issue#IANKQ1@Gitee)
+* 【http 】 HttpConfig增加`setUseDefaultContentTypeIfNull`方法(issue#3719@Github)
### 🐞Bug修复
* 【json 】 修复JSONConfig.setDateFormat设置后toBean无效问题(issue#3713@Github)
diff --git a/hutool-http/src/main/java/cn/hutool/http/HttpConfig.java b/hutool-http/src/main/java/cn/hutool/http/HttpConfig.java
index 72fd765ce..1378a4c82 100755
--- a/hutool-http/src/main/java/cn/hutool/http/HttpConfig.java
+++ b/hutool-http/src/main/java/cn/hutool/http/HttpConfig.java
@@ -94,6 +94,11 @@ public class HttpConfig {
* 自动重定向时是否处理cookie
*/
boolean followRedirectsCookie;
+ /**
+ * issue#3719 如果为true,则当请求头中Content-Type为空时,使用默认的Content-Type,即application/x-www-form-urlencoded
+ * @since 5.8.33
+ */
+ boolean useDefaultContentTypeIfNull = true;
/**
* 设置超时,单位:毫秒
@@ -314,4 +319,15 @@ public class HttpConfig {
this.followRedirectsCookie = followRedirectsCookie;
return this;
}
+
+ /**
+ * 设置是否使用默认Content-Type,如果请求中未设置Content-Type,是否使用默认值
+ * @param useDefaultContentTypeIfNull 是否使用默认Content-Type
+ * @return this
+ * @since 5.8.33
+ */
+ public HttpConfig setUseDefaultContentTypeIfNull(boolean useDefaultContentTypeIfNull) {
+ this.useDefaultContentTypeIfNull = useDefaultContentTypeIfNull;
+ return this;
+ }
}
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 10aa74c9e..03fe8f1ec 100755
--- a/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java
+++ b/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java
@@ -1358,7 +1358,7 @@ public class HttpRequest extends HttpBase {
* @throws IOException IO异常
*/
private void sendFormUrlEncoded() throws IOException {
- if (StrUtil.isBlank(this.header(Header.CONTENT_TYPE))) {
+ if (this.config.useDefaultContentTypeIfNull && StrUtil.isBlank(this.header(Header.CONTENT_TYPE))) {
// 如果未自定义Content-Type,使用默认的application/x-www-form-urlencoded
this.httpConnection.header(Header.CONTENT_TYPE, ContentType.FORM_URLENCODED.toString(this.charset), true);
}