![](/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.