android - 为什么 OKHttp 设计成 SocketTimeoutException 时不重试

标签 android http okhttp

private boolean isRecoverable(IOException e, boolean requestSendStarted) {
    ....
    // If there was an interruption don't recover, but if there was a 
    //timeout connecting to a route
    // we should try the next route (if there is one).
     if (e instanceof InterruptedIOException) {
      return e instanceof SocketTimeoutException && !requestSendStarted;
    }
   ....
    return true;
}

这是 RetryAndFollowUpInterceptor 中的代码 fragment 在 OKHttp 中。

我的问题是为什么 OkHttpSocketTimeoutException 和 requestSendStarted == true 时不重试?

因为我觉得如果有一些其他的router,我们可以换个ip或者router重试

最佳答案

考虑这样一种情况,请求已成功发送,但在将响应数据传输到客户端时出现了问题。在这种情况下,自动重试可能会使服务器重复某些可能不需要的操作(增加一些计数,在某处写入记录)。 OKHttp 让用户决定在这种情况下要做什么。

关于android - 为什么 OKHttp 设计成 SocketTimeoutException 时不重试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46320652/

相关文章:

java - 如何防止我的小部件在首次运行时更新?

image - 在 http golang 中提供来自字符串的图像

java - OkHttp 是否在重定向时发送授权和其他可能敏感的 header ?

android - 使用 android intent 与 appcelerator 共享文件

c# - 按后退按钮时显示警报

javascript - 处理多个http调用和多个响应

node.js - 建议 : Tracking HTTP requests with CloudFlare and Ghost

android - 为 WebTokens 身份验证改造自定义客户端

java.lang.NoClassDefFoundError : okhttp3. OkHttpClient$Builder

java - 无法在 Google Play 上上传应用,证书无效