Android HttpClient Exception Control issue (Manager is shut down)

余生颓废 提交于 2019-12-25 08:58:29

问题


My app posts some strings to my server.
It use HttpClient to send datas.
All functions are perfect without 1 problem..

If My phone is on networking state then
I click submit button -> Datas can be send on my server. (real very well)

If My phone is unnetworking(disconneing) state (it means not using wifi or 3g...)
I click submit button -> It showing up Error Dialog as 'You have to check network'

But Problem is...
As soon as(about in 0.5~1.5 seconds) I click wifi enable button then I click submit button,
The HttpClient post execution showing up exception problem.(FC)
Can I control the exception problem? I want showing up error dialog but, The exception, I can't control.
I think during wifi is enabling (or 3g), the execution something happen problems.

This is error sentence
02-06 00:48:41.250: E/AndroidRuntime(20183): Caused by: java.lang.IllegalStateException: Manager is shut down.

The Source

(...ready for setting params, and string datas..and so on)

            HttpPost httpPost = new HttpPost(url);
            try {
                httpPost.setEntity(mpEntity);
                httpPost.addHeader("cookie", cookie);

                //↓This execute is problem. How can I control exception?
                HttpResponse response = httpClient.execute(httpPost);

                HttpEntity resEntity = response.getEntity();
                InputStream content = resEntity.getContent();
                return content;
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            httpClient.getConnectionManager().shutdown();
            return null;
        }

回答1:


I think the problematic line is

        httpClient.getConnectionManager().shutdown();

This is the original Apache documentation, without more code (and the full stack trace) is difficult to understand what's going on. I think it's just bad API usage



来源:https://stackoverflow.com/questions/9150700/android-httpclient-exception-control-issue-manager-is-shut-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!