Android:无效使用SingleClientConnManager:添加consumeContent()后仍然分配连接

时间:2014-07-06 19:03:51

标签: android androidhttpclient

我正在尝试按照https://stackoverflow.com/questions/24591165/android-http-reponse-code-error中的讨论创建一个通过http帖子登录的活动。无论如何,经过测试,我一直在我的logcat中收到以下两个警告:

  

07-06 11:55:16.934:W / SingleClientConnManager(1049):无效使用   SingleClientConnManager:仍然分配连接。 07-06   11:55:16.934:W / SingleClientConnManager(1049):确保释放   分配另一个之前的连接。

我做了一些关于stackoverflow的搜索,我尝试在人们推荐时添加以下代码:

    response.getEntity().consumeContent();

但我仍然收到一些警告。这是我的帖子请求函数的代码:

private void sendRequest() {
        // TODO Auto-generated method stub
        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("username", username));
            nameValuePairs.add(new BasicNameValuePair("password", password));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);
            status = response.getStatusLine().getStatusCode();
            response.getEntity().consumeContent();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }
    }

你们认为我做错了什么?

1 个答案:

答案 0 :(得分:0)

我可以通过以下解决方案解决此问题:http://tech.chitgoks.com/2011/05/05/fixing-the-invalid-use-of-singleclientconnmanager-connection-still-allocated-problem/

希望这能解决你的问题。

相关问题