mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix http bug
This commit is contained in:
@@ -444,9 +444,21 @@ public class HttpConnection {
|
||||
throw new IOException("HttpURLConnection has not been initialized.");
|
||||
}
|
||||
|
||||
final Method method = getMethod();
|
||||
|
||||
// 当有写出需求时,自动打开之
|
||||
this.conn.setDoOutput(true);
|
||||
return this.conn.getOutputStream();
|
||||
final OutputStream out = this.conn.getOutputStream();
|
||||
|
||||
// 解决在Rest请求中,GET请求附带body导致GET请求被强制转换为POST
|
||||
// 在sun.net.www.protocol.http.HttpURLConnection.getOutputStream0方法中,会把GET方法
|
||||
// 修改为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());
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user