Httpclient.setHttpRequestRetryHandler(requestRetryHandler);


/**
 * 设置重连机制和异常自动恢复处理
 */
private static HttpRequestRetryHandler requestRetryHandler = new HttpRequestRetryHandler() {
// 自定义的恢复策略
public boolean retryRequest(IOException exception, int executionCount,
HttpContext context) {
// 设置恢复策略,在Http请求发生异常时候将自动重试3次
if (executionCount >= 3) {
// Do not retry if over max retry count
return false;
}
if (exception instanceof NoHttpResponseException) {
// Retry if the server dropped connection on us
return true;
}
if (exception instanceof SSLHandshakeException) {
// Do not retry on SSL handshake exception
return false;
}
HttpRequest request = (HttpRequest) context
.getAttribute(ExecutionContext.HTTP_REQUEST);
boolean idempotent = (request instanceof HttpEntityEnclosingRequest);
if (!idempotent) {
// Retry if the request is considered idempotent
return true;
}
return false;
}
};

更多相关文章

  1. Android中的Handler消息机制
  2. Android IPC 机制【2】--- Messenger[1]
  3. Android wifi休眠策略
  4. 【Android策略】The content of the adapter has changed but Li
  5. Watchdog 工作机制解析
  6. Android View刷新机制
  7. Android Handler消息机制(源码分析)

随机推荐

  1. Android常见40道原理性面试,去面试之前必
  2. 蒸蒸日上的智能手机,国产手机却迎来寒冬,因
  3. 移动端启动速度
  4. Android(安卓)系统启动流程解析-从开机到
  5. Android(安卓)studio 使用原生自带Downlo
  6. Android(安卓)内存查看常用命令
  7. Android(安卓)app如何正确读写系统sys设
  8. 字节跳动屏幕适配方案解读
  9. Android(安卓)wifi 信号强度单位 dbm
  10. Android屏幕录制并转换gif