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
Android 网络连接-重试机制-HttpRequestRetryHandler(HttpClient)
最新推荐文章于 2024-06-26 21:42:29 发布
本文介绍了如何在Android中使用HttpClient设置网络连接的重试机制。通过自定义HttpRequestRetryHandler,当HTTP请求发生异常时,系统会自动重试3次。具体实现包括对NoHttpResponseException的处理和区分幂等与非幂等请求。
摘要由CSDN通过智能技术生成