mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
HttpConfig增加配置setUseGetIfRedirect
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user