0

我收到 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() 吗?

4

1 回答 1

0

You should probably utilize an EntityUtils.consume() to consume any remaining content in the stream if you have not already done so.

Or take @dnault's suggestion and close the stream.

于 2013-10-31T17:04:09.507 回答