![](/img/trans.png)
[英]Invalid use of SingleClientConnManager: connection still allocated
[英]apache HttpClient: Invalid use of SingleClientConnManager
我正在獲取java.lang.IllegalStateException:SingleClientConnManager的無效使用:連接仍被分配。 我使用的代碼如下:
HttpResponse targetResponse = getHttpClient(true).execute(post,
localContext);
BufferedReader rd = new BufferedReader(new InputStreamReader(
targetResponse.getEntity().getContent()));
String line = new String();
while ((line = rd.readLine()) != null) {
if (!line.contains("attr1") && !line.contains("attr2"))
continue;
String[] splits = line.split(": ");
if (splits[0].contains("attr1")) {
attr1 = splits[1].trim();
} else {
attr2 = splits[1].trim();
}
if (attr1 != null && attr2 != null)
break;
}
我的理解是,一旦我執行targetResponse.getEntity(),就應該使用該實體。 我是否還需要進行顯式調用EntityUtils.consume()?
如果尚未使用EntityUtils.consume()來消耗流中的所有剩余內容,則可能應該使用。
或接受@dnault的建議並關閉流。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.