限制Authenticator的重试次数

Ixx*_*Ixx 3 android okhttp

Authenticator当我收到身份验证质询 (401) 时,我扩展以检索授权和身份验证令牌。它会重试 20 次。有没有办法设置不同的计数(我想将其设置为 3)?

为了以防万一,我将 OkHttp(3) 与 Retrofit2 结合使用。

Jes*_*son 6

请参阅处理身份验证文档:

private int responseCount(Response response) {
  int result = 1;
  while ((response = response.priorResponse()) != null) {
    result++;
  }
  return result;
}
Run Code Online (Sandbox Code Playgroud)

  • 谢谢你!如果这些信息更容易获取,那就太好了。很难找到埋藏在“食谱”中的东西。 (3认同)
  • 注意:重试逻辑仅包含在 @Jesse Wilson 链接到的示例代码的 Java 版本中,而不包含在 Kotlin 版本中。 (2认同)