这个问题困扰了好久,今天解决了,高兴了一下,就是每次去请求,第一次都不会返回数据
android在wifi下使用HttpClient 4.0,在项目中有时会发生如下错误,尤其是第一次网络请求的时候
加上这个就OK了:
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);
最后发自肺腑感叹一句stackoverflow大神多啊