gpt4 book ai didi

java - Android 无效使用 SingleClientConnManager : connection still allocated

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:07:32 27 4
gpt4 key购买 nike

请注意,这个问题对于我的 HTTP 调用来说是独一无二的。

我环顾四周,有人说 httpResponse.getEntity().consumeContent();

但是我可以使用它,因为我需要提供一个返回数据。

我调用我的 API doInBackground.... return api.post("analytics", params);

如何将无效的 SingleClientConnManager 修复到此 http 帖子中:

public String post(String url, List<NameValuePair> params) {
HttpPost request = new HttpPost(BASEURL + url);
HttpResponse response;

try {
request.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
response = client.execute(request);
HttpEntity entity = response.getEntity();

return EntityUtils.toString(entity);
}
catch(ClientProtocolException e) {
return e.toString();
}
catch(IOException e) {
return e.toString();
}
}//end post

这是我遇到的错误:

03-12 12:33:46.926: V/Activity(28803): YourAsyncTask.class
03-12 12:33:46.926: W/Activity(28803): -------------------------------------------------
03-12 12:33:46.926: W/SingleClientConnManager(28803): Invalid use of SingleClientConnManager: connection still allocated.
03-12 12:33:46.926: W/SingleClientConnManager(28803): Make sure to release the connection before allocating another one.
03-12 12:33:46.926: I/System.out(28803): AsyncTask #4 calls detatch()
03-12 12:33:46.926: D/Toast(28803): checkMirrorLinkEnabled returns : false
03-12 12:33:46.926: D/Toast(28803): showing allowed
03-12 12:33:46.926: W/AsyncTaskExecutor(28803): java.util.concurrent.ThreadPoolExecutor$Worker@433abe80[State = -1, empty queue] | AsyncTask # 5

最佳答案

经过搜索,I found this solution

HttpResponse httpResponse = httpClient.execute(httpPost);

//instead of httpClient use getThreadSafeClient() method.
HttpResponse httpResponse = getThreadSafeClient().execute(httpPost);

public static DefaultHttpClient getThreadSafeClient() {
        DefaultHttpClient client = new DefaultHttpClient();
        ClientConnectionManager mgr = client.getConnectionManager();
        HttpParams params = client.getParams();
    client = new DefaultHttpClient(new ThreadSafeClientConnManager(params,
                mgr.getSchemeRegistry()), params);
   
        return client;
    }

关于java - Android 无效使用 SingleClientConnManager : connection still allocated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29001784/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com