方法实在是很简单, 为你的httpclient添加一个retryhandler就ok了。代码如下:
HttpRequestRetryHandler retryHandler = new HttpRequestRetryHandler() {
@Override
public boolean retryRequest(IOException arg0, int arg1, HttpContext arg2) {
// retry a max of 5 times
if (arg1 >= 3) {
return false;
}
if (arg0 instanceof ch.boye.httpclientandroidlib.NoHttpResponseException) {
return true;
} else if (arg0 instanceof ch.boye.httpclientandroidlib.client.ClientProtocolException) {
return true;
}
return false;
}
};
sHttpClient.setHttpRequestRetryHandler(retryHandler);
如果上面的代码不好使的话,可以试着添加:
HttpProtocolParams.setUseExpectContinue(params, false);