android 使用 httpClient 从服务器端读取数据,出现异常

这个问题困扰了很久,今天解决了,高兴了一下,就是每次去请求,第一次都不会返回数据
android在wifi下使用HttpClient 4.0,在项目中有时会发生以下错误,尤为是第一次网络请求的时候
加上这个就OK了: java

        HttpProtocolParams.setUseExpectContinue(httpParams, false);
        HttpRequestRetryHandler retryHandler = new HttpRequestRetryHandler() {

            public boolean retryRequest(IOException exception, int executionCount,
                    HttpContext context) {
                // retry a max of 5 times
                if(executionCount >= 5){
                    return false;
                }
                if(exception instanceof NoHttpResponseException){
                    return true;
                } else if (exception instanceof ClientProtocolException){
                    return true;
                } 
                return false;
            }
        };
        httpClient.setHttpRequestRetryHandler(retryHandler);

这是解决地址源地址http://stackoverflow.com/questions/2052299/httpclient-on-android-nohttpresponseexception-through-umts-3g android

最后发自肺腑感叹一句stackoverflow大神多啊 网络

相关文章
相关标签/搜索