okhttp3.internal.platform.Platform.log A connection to xxxxx was leaked

qq_36153042 2017-07-22 01:12:43
package com.dtdream.watchman.common.utils;

import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.http.HttpHeaders;

import java.io.IOException;

public class HttpClientUtil {

private OkHttpClient httpClient;

public HttpClientUtil() {
httpClient = new OkHttpClient.Builder().followRedirects(false).build();
}

public String executeRequest(Request req) throws IOException {
Response resp = null;
String respBody = null;

try {
resp = httpClient.newCall(req).execute();

if (resp.isRedirect()) {
resp.close();
HttpUrl redirectUrl = req.url().newBuilder(resp.header(HttpHeaders.LOCATION))
.query(req.url().query())
.build();
Request newReq = req.newBuilder().url(redirectUrl).build();
respBody = executeRequest(newReq);
} else {
respBody = resp.body().string();
}

if (!resp.isSuccessful()) {
resp.body().close();
resp.close();
throw new IOException(resp.toString());
}
} catch (Exception e) {
if (resp != null) {
resp.body().close();
resp.close();
}
}
return respBody;
}
}
okhttp3.internal.platform.Platform.log A connection to http://xxxxxxxxx was leaked. Did you forget to close a response body?

大神帮忙解释一下这是为什么啊
...全文
1510 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧