mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.reflect.ReflectUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.net.URLUtil;
|
||||
import cn.hutool.core.reflect.FieldUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.http.ssl.DefaultSSLInfo;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
@@ -453,7 +453,7 @@ public class HttpConnection {
|
||||
// 修改为POST,而且无法调用setRequestMethod方法修改,因此此处使用反射强制修改字段属性值
|
||||
// https://stackoverflow.com/questions/978061/http-get-with-request-body/983458
|
||||
if(method == Method.GET && method != getMethod()){
|
||||
ReflectUtil.setFieldValue(this.conn, "method", Method.GET.name());
|
||||
FieldUtil.setFieldValue(this.conn, "method", Method.GET.name());
|
||||
}
|
||||
|
||||
return out;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.reflect.FieldUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.reflect.ReflectUtil;
|
||||
import cn.hutool.http.cookie.GlobalCookieManager;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -192,20 +192,20 @@ public class HttpGlobalConfig implements Serializable {
|
||||
if (isAllowPatch) {
|
||||
return;
|
||||
}
|
||||
final Field methodsField = ReflectUtil.getField(HttpURLConnection.class, "methods");
|
||||
final Field methodsField = FieldUtil.getField(HttpURLConnection.class, "methods");
|
||||
if (null == methodsField) {
|
||||
throw new HttpException("None static field [methods] with Java version: [{}]", System.getProperty("java.version"));
|
||||
}
|
||||
|
||||
// 去除final修饰
|
||||
ReflectUtil.setFieldValue(methodsField, "modifiers", methodsField.getModifiers() & ~Modifier.FINAL);
|
||||
FieldUtil.setFieldValue(methodsField, "modifiers", methodsField.getModifiers() & ~Modifier.FINAL);
|
||||
final String[] methods = {
|
||||
"GET", "POST", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE", "PATCH"
|
||||
};
|
||||
ReflectUtil.setFieldValue(null, methodsField, methods);
|
||||
FieldUtil.setFieldValue(null, methodsField, methods);
|
||||
|
||||
// 检查注入是否成功
|
||||
final Object staticFieldValue = ReflectUtil.getStaticFieldValue(methodsField);
|
||||
final Object staticFieldValue = FieldUtil.getStaticFieldValue(methodsField);
|
||||
if (false == ArrayUtil.equals(methods, staticFieldValue)) {
|
||||
throw new HttpException("Inject value to field [methods] failed!");
|
||||
}
|
||||
|
Reference in New Issue
Block a user