【问题标题】:com.squareup.okhttp : Too many follow-up requests: 21com.squareup.okhttp : 后续请求太多:21
【发布时间】:2022-01-21 21:26:35
【问题描述】:

我有实现 Authenticator 接口的 ProxyAuthenticator 类。

public class ProxyAuthenticator implements Authenticator {

private String  proxyUser;
private String  proxyPassword;

public ProxyTessiAuthenticator(String proxyUser, String proxyPassword) {
    this.proxyUser = proxyUser;
    this.proxyPassword = proxyPassword;
}

@Override
public Request authenticateProxy(Proxy proxy, Response response) throws IOException {
    return authenticate(proxy, response);
}

@Override
public Request authenticate(Proxy proxy, Response response) throws IOException {
    String credential = Credentials.basic(proxyUser, proxyPassword);
    return response.request().newBuilder()
            .header("Proxy-Authorization", credential)
            .build();
}

}

我通过 com.squareup.okhttp 得到了这个异常:

java.net.ProtocolException: 后续请求太多:21

【问题讨论】:

    标签: java http authentication proxy okhttp


    【解决方案1】:

    如果您已经尝试过,则需要将其他身份验证请求短路。

    https://github.com/square/okhttp/blob/3a6646dfd61cf55e3db38ebd08c7e504dde7a4bd/docs/recipes.md#handling-authentication-kt-java

    https://howtoprogram.xyz/2016/11/03/basic-authentication-okhttp-example/

            public Request authenticate(Route route, Response response) throws IOException {
                String credential = ...
                if (responseCount(response) >= 3) {
                    return null;
                }
                return response.request().newBuilder().header("Authorization", credential).build();
            }
    

    【讨论】:

      猜你喜欢
      • 2016-05-10
      • 2017-03-29
      • 1970-01-01
      • 2018-07-13
      • 2012-03-31
      • 2021-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多