我正在使用okhttp3,并试图了解如何通过userId & pswd向只接受HTTPS协议的代理服务器进行身份验证。我已经在其他网站(链接如下)上看到了exmaple over SO,但他们没有HTTPS协议。
https://botproxy.net/docs/how-to/okhttpclient-proxy-authentication-how-to/
谁能告诉我如何使用HTTPS协议呼叫代理服务器?
发布于 2021-10-01 05:54:16
它不是官方支持的,但有一个解决方法。
https://github.com/square/okhttp/issues/6561
Authenticator proxyAuthenticator = new Authenticator() {
@Override public Request authenticate(Route route, Response response) throws IOException {
String credential = Credentials.basic(username, password);
return response.request().newBuilder().header("Proxy-Authorization", credential).build();
}
};
OkHttpClient client = new OkHttpClient.Builder()
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)))
.proxyAuthenticator(proxyAuthenticator);
.socketFactory(new DelegatingSocketFactory(SSLSocketFactory.getDefault()))
.build();https://stackoverflow.com/questions/69399127
复制相似问题