我收到 java.lang.IllegalStateException: Invalid use of 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() 吗?