gpt4 book ai didi

android - OkHttpClient 是否有最大重试次数

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:23:41 66 4
gpt4 key购买 nike

我正在为 OkHttpClient 设置连接失败时重试选项。

client = new OkHttpClient();
client.setRetryOnConnectionFailure(true);

我想知道它会继续尝试多少次。看着 source code我没有看到任何最大限​​制。如何配置客户端在尝试几次后停止尝试?

最佳答案

这里有更多文档https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.Builder.html#retryOnConnectionFailure-boolean-

Configure this client to retry or not when a connectivity problem is encountered. By default, this client silently recovers from the following problems:

  • Unreachable IP addresses. If the URL's host has multiple IP addresses, failure to reach any individual IP address doesn't fail the overall request. This can increase availability of multi-homed services.
  • Stale pooled connections. The ConnectionPool reuses sockets to decrease request latency, but these connections will occasionally time out.

  • Unreachable proxy servers. A ProxySelector can be used to attempt multiple proxy servers in sequence, eventually falling back to a direct connection.

Set this to false to avoid retrying requests when doing so is destructive. In this case the calling application should do its own recovery of connectivity failures.

但总的来说,我认为它的目的是在存在现有的失效连接或可以重试的替代路径时重试。不要无限期地重试完全相同的事情。

另见 ConnectionSpecSelector.connectionFailed

关于android - OkHttpClient 是否有最大重试次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37883418/

66 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com