mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-07 06:08:00 +08:00
修复https下可能的Patch、Get请求失效问题
This commit is contained in:
parent
6bdd6924ea
commit
f9610d523d
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
|
* 【http 】 修复https下可能的Patch、Get请求失效问题(issue#I3Z3DH@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -128,9 +128,13 @@ public class HttpConnection {
|
|||||||
try {
|
try {
|
||||||
this.conn.setRequestMethod(method.toString());
|
this.conn.setRequestMethod(method.toString());
|
||||||
} catch (ProtocolException e) {
|
} catch (ProtocolException e) {
|
||||||
|
if(Method.PATCH.equals(method)){
|
||||||
|
// 如果全局设置失效,此处针对单独链接重新设置
|
||||||
|
reflectSetMethod(method);
|
||||||
|
}else{
|
||||||
throw new HttpException(e);
|
throw new HttpException(e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,7 +457,7 @@ public class HttpConnection {
|
|||||||
// 修改为POST,而且无法调用setRequestMethod方法修改,因此此处使用反射强制修改字段属性值
|
// 修改为POST,而且无法调用setRequestMethod方法修改,因此此处使用反射强制修改字段属性值
|
||||||
// https://stackoverflow.com/questions/978061/http-get-with-request-body/983458
|
// https://stackoverflow.com/questions/978061/http-get-with-request-body/983458
|
||||||
if(method == Method.GET && method != getMethod()){
|
if(method == Method.GET && method != getMethod()){
|
||||||
ReflectUtil.setFieldValue(this.conn, "method", Method.GET.name());
|
reflectSetMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
@ -544,5 +548,19 @@ public class HttpConnection {
|
|||||||
private URLConnection openConnection() throws IOException {
|
private URLConnection openConnection() throws IOException {
|
||||||
return (null == this.proxy) ? url.openConnection() : url.openConnection(this.proxy);
|
return (null == this.proxy) ? url.openConnection() : url.openConnection(this.proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过反射设置方法名,首先设置HttpURLConnection本身的方法名,再检查是否为代理类,如果是,设置带路对象的方法名。
|
||||||
|
* @param method 方法名
|
||||||
|
*/
|
||||||
|
private void reflectSetMethod(Method method){
|
||||||
|
ReflectUtil.setFieldValue(this.conn, "method", method.name());
|
||||||
|
|
||||||
|
// HttpsURLConnectionImpl实现中,使用了代理类,需要修改被代理类的method方法
|
||||||
|
final Object delegate = ReflectUtil.getFieldValue(this.conn, "delegate");
|
||||||
|
if(null != delegate){
|
||||||
|
ReflectUtil.setFieldValue(delegate, "method", method.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
// --------------------------------------------------------------- Private Method end
|
// --------------------------------------------------------------- Private Method end
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user