這個問題困擾了很久,今天解決了,高興了一下,就是每次去請求,第一次都不會返回數據
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大神多啊 網絡