This commit is contained in:
Looly
2022-10-22 18:43:43 +08:00
parent a82cf11365
commit d748366dfe
2 changed files with 31 additions and 10 deletions

View File

@@ -72,7 +72,6 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
* @param isIgnoreBody 是否忽略读取响应体 * @param isIgnoreBody 是否忽略读取响应体
* @since 3.1.2 * @since 3.1.2
*/ */
@SuppressWarnings("resource")
protected HttpResponse(final HttpConnection httpConnection, final HttpConfig config, final Charset charset, final boolean isAsync, final boolean isIgnoreBody) { protected HttpResponse(final HttpConnection httpConnection, final HttpConfig config, final Charset charset, final boolean isAsync, final boolean isIgnoreBody) {
this.httpConnection = httpConnection; this.httpConnection = httpConnection;
this.config = config; this.config = config;
@@ -479,18 +478,15 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
* 3、持有Http流并不关闭流 * 3、持有Http流并不关闭流
* </pre> * </pre>
* *
* @return this
* @throws HttpException IO异常 * @throws HttpException IO异常
*/ */
@SuppressWarnings("resource") private void initWithDisconnect() throws HttpException {
private HttpResponse initWithDisconnect() throws HttpException {
try { try {
init(); init();
} catch (final HttpException e) { } catch (final HttpException e) {
this.httpConnection.disconnectQuietly(); this.httpConnection.disconnectQuietly();
throw e; throw e;
} }
return this;
} }
/** /**
@@ -503,10 +499,10 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
* 3、持有Http流并不关闭流 * 3、持有Http流并不关闭流
* </pre> * </pre>
* *
* @return this
* @throws HttpException IO异常 * @throws HttpException IO异常
*/ */
private HttpResponse init() throws HttpException { @SuppressWarnings("resource")
private void init() throws HttpException {
// 获取响应状态码 // 获取响应状态码
try { try {
this.status = httpConnection.responseCode(); this.status = httpConnection.responseCode();
@@ -517,7 +513,6 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
// 服务器无返回内容,忽略之 // 服务器无返回内容,忽略之
} }
// 读取响应头信息 // 读取响应头信息
try { try {
this.headers = httpConnection.headers(); this.headers = httpConnection.headers();
@@ -526,6 +521,7 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
// StaticLog.warn(e, e.getMessage()); // StaticLog.warn(e, e.getMessage());
} }
// 存储服务端设置的Cookie信息 // 存储服务端设置的Cookie信息
GlobalCookieManager.store(httpConnection, this.headers); GlobalCookieManager.store(httpConnection, this.headers);
@@ -540,7 +536,9 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
this.in = new HttpInputStream(this); this.in = new HttpInputStream(this);
// 同步情况下强制同步 // 同步情况下强制同步
return this.isAsync ? this : forceSync(); if (!this.isAsync) {
forceSync();
}
} }
/** /**
@@ -641,6 +639,5 @@ public class HttpResponse extends HttpBase<HttpResponse> implements Closeable {
} }
return fileName; return fileName;
} }
// ---------------------------------------------------------------- Private method end // ---------------------------------------------------------------- Private method end
} }

View File

@@ -0,0 +1,24 @@
package cn.hutool.http;
import cn.hutool.json.JSONUtil;
import org.junit.Ignore;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
public class IssueI5WAV4Test {
@Test
@Ignore
public void getTest(){
//测试代码
final Map<String, Object> map = new HashMap<>();
map.put("taskID", 370);
map.put("flightID", 2879);
final String body = HttpRequest.get("http://localhost:8884/api/test/testHttpUtilGetWithBody").body(JSONUtil.toJsonStr(map)).execute().body();
System.out.println("使用hutool返回结果:" + body);
}
}