HttpClient on Android : NoHttpResponseException through UMTS/3G

I ran into this issue as well. It only occurred sporadically, usually on an initial http request. Subsequent requests would work fine. Adding setUseExpectContinue didn’t seem to work.

The solution in my case was to add a retry handler that would retry the request on specific exceptions:

        HttpProtocolParams.setUseExpectContinue(client.getParams(), 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;
            }
        };
        client.setHttpRequestRetryHandler(retryHandler);

Leave a Comment