嚴格模式會投訴以下內容:資源是在附加的堆棧跟蹤中獲取的,但從未發佈。見java.io.Closeable的信息,避免資源泄漏:嚴格模式對資源泄漏抱怨
**response = httpclient.execute(httpPost);**
下面是我的代碼:
HttpClient httpclient = new DefaultHttpClient();
String url = "example";
HttpPost httpPost = new HttpPost(url);
HttpResponse response;
String responseString = "";
try {
httpPost.setHeader("Content-Type", "application/json");
**response = httpclient.execute(httpPost);**
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
responseString = out.toString();
} else {
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
return responseString;
在此先感謝。
你關閉你的HTTP客戶端上的最終塊...'的HttpClient .getConnectionManager()。shutdown(); ...' –
感謝大家。 – muneikh