1
我在執行此代碼時收到以下錯誤消息。http調用執行中的資源泄漏
資源在附加的堆棧跟蹤中獲取,但從未發佈。有關避免資源泄漏的信息,請參閱java.io.Closeable .:
我無法確定下面代碼中的資源泄漏。如果有人指出我究竟做錯了什麼,我會很感激。
HttpPost request = new HttpPost(url);
StringBuilder sb = new StringBuilder();
StringEntity entity = new StringEntity(jsonString);
entity.setContentType("application/json;charset=UTF-8");
entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json;charset=UTF-8"));
request.setHeader("Accept", "application/json");
request.setEntity(entity);
HttpResponse response = null;
DefaultHttpClient httpclient = getHttpClientImpl();
BufferedReader reader = null;
InputStream in = null;
try {
response = httpclient.execute(request);
in = response.getEntity().getContent();
reader = new BufferedReader(new InputStreamReader(in));
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} catch (Exception se) {
Log.e("Exception", se + "");
throw se;
} finally {
if (in != null)
in.close();
if (reader != null)
reader.close();
if (client != null && client.getConnectionManager() != null) {
client.getConnectionManager().shutdown();
}
}
return sb.toString();