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
中。
我的问题是为什么 OkHttp
在 SocketTimeoutException
和 requestSendStarted == true 时不重试?
因为我觉得如果有一些其他的router,我们可以换个ip或者router重试
最佳答案
考虑这样一种情况,请求已成功发送,但在将响应数据传输到客户端时出现了问题。在这种情况下,自动重试可能会使服务器重复某些可能不需要的操作(增加一些计数,在某处写入记录)。 OKHttp 让用户决定在这种情况下要做什么。
关于android - 为什么 OKHttp 设计成 SocketTimeoutException 时不重试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46320652/