mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 08:37:26 +08:00
HttpConfig增加配置setUseGetIfRedirect
This commit is contained in:
parent
5da69e1f40
commit
cefc0fd559
@ -2,7 +2,7 @@
|
||||
# 🚀Changelog
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.33(2024-09-05)
|
||||
# 5.8.33(2024-09-06)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 SyncFinisher增加setExecutorService方法(issue#IANKQ1@Gitee)
|
||||
@ -10,6 +10,7 @@
|
||||
* 【core 】 用ArrayList重新实现权重随机类:WeightListRandom(pr#3720@Github)
|
||||
* 【crypto 】 SM2解密时,兼容GmSSL非压缩省略的04头的密文(issue#IAP1QJ@Gitee)
|
||||
* 【core 】 兼容NumberUtil.add方法传入整型自动类型转换为浮点类型的精度丢失问题(pr#3721@Github)
|
||||
* 【http 】 HttpConfig增加配置setUseGetIfRedirect(issue#3722@Github)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【json 】 修复JSONConfig.setDateFormat设置后toBean无效问题(issue#3713@Github)
|
||||
|
@ -96,9 +96,15 @@ public class HttpConfig {
|
||||
boolean followRedirectsCookie;
|
||||
/**
|
||||
* issue#3719 如果为true,则当请求头中Content-Type为空时,使用默认的Content-Type,即application/x-www-form-urlencoded
|
||||
*
|
||||
* @since 5.8.33
|
||||
*/
|
||||
boolean useDefaultContentTypeIfNull = true;
|
||||
/**
|
||||
* 当重定向时,是否使用Get方式发送请求<br>
|
||||
* issue#3722 部分请求要求重定向时,必须使用Get方式发送请求
|
||||
*/
|
||||
boolean useGetIfRedirect;
|
||||
|
||||
/**
|
||||
* 设置超时,单位:毫秒<br>
|
||||
@ -186,7 +192,7 @@ public class HttpConfig {
|
||||
*/
|
||||
public HttpConfig setHttpProxy(String host, int port) {
|
||||
final Proxy proxy = new Proxy(Proxy.Type.HTTP,
|
||||
new InetSocketAddress(host, port));
|
||||
new InetSocketAddress(host, port));
|
||||
return setProxy(proxy);
|
||||
}
|
||||
|
||||
@ -322,6 +328,7 @@ public class HttpConfig {
|
||||
|
||||
/**
|
||||
* 设置是否使用默认Content-Type,如果请求中未设置Content-Type,是否使用默认值
|
||||
*
|
||||
* @param useDefaultContentTypeIfNull 是否使用默认Content-Type
|
||||
* @return this
|
||||
* @since 5.8.33
|
||||
@ -330,4 +337,16 @@ public class HttpConfig {
|
||||
this.useDefaultContentTypeIfNull = useDefaultContentTypeIfNull;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重定向时是否使用GET方式
|
||||
*
|
||||
* @param useGetIfRedirect 重定向时是否使用GET方式
|
||||
* @return this
|
||||
* @since 5.8.33
|
||||
*/
|
||||
public HttpConfig setUseGetIfRedirect(boolean useGetIfRedirect) {
|
||||
this.useGetIfRedirect = useGetIfRedirect;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -1313,9 +1313,13 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
redirectUrl = UrlBuilder.ofHttpWithoutEncode(location);
|
||||
}
|
||||
setUrl(redirectUrl);
|
||||
if(config.useGetIfRedirect){
|
||||
// since 5.8.33, issue#3722
|
||||
setMethod(Method.GET);
|
||||
}
|
||||
if (redirectCount < config.maxRedirectCount) {
|
||||
redirectCount++;
|
||||
// 重定向不再走过滤器
|
||||
// 重定向可选是否走过滤器
|
||||
return doExecute(isAsync, config.interceptorOnRedirect ? config.requestInterceptors : null,
|
||||
config.interceptorOnRedirect ? config.responseInterceptors : null);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user