okhttp3.internal.platform.Platform.log A connection to xxxxx was leaked
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?
大神帮忙解释一下这是为什么啊