gpt4 book ai didi

java - apache httpclient 使用 https 代理 : peer not authenticated

转载 作者:太空宇宙 更新时间:2023-11-03 15:00:59 39 4
gpt4 key购买 nike

我正在尝试将 hidemyass.com ( https://hidemyass.com/proxy-list/search-225434 ) 上的免费 https-proxy-servers 大列表之一与 apache httpclient 4.1 一起使用。我现在已经尝试了几乎所有的方法,但我总是得到 javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated所以我用谷歌搜索,发现没有服务器有对等证书,例如:

> openssl s_client -tls1 -showcerts -connect 109.75.178.230:3128  
CONNECTED(00000003)
139856907785896:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number:s3_pkt.c:337:

no peer certificate available

No client certificate CA names sent

SSL handshake has read 5 bytes and written 7 bytes

New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
SSL-Session:
Protocol : TLSv1
Cipher : 0000
Session-ID:
Session-ID-ctx:
Master-Key:
Key-Arg : None
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1393183549
Timeout : 7200 (sec)
Verify return code: 0 (ok)

当我尝试在同一端口上切换到 http 时,它可以正常工作,但在 hidemyass 上的代理列表中,类型是 https。所以我现在不知道该怎么办...请帮忙。

如果您需要查看我的代码:http://paste.debian.net/83674/

最佳答案

所以如果你没问题,你可以信任下面的所有证书

final TrustStrategy trustStrategy = new TrustStrategy() {

@Override
public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException {
return true;
}
};
SSLContext sslcontext = null;
try {
sslcontext = SSLContexts.custom().loadTrustMaterial(null, trustStrategy).build();
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
socketFactory = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

然后使用

创建您的 HTTPClient
httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();

这将确保所有 https 调用的证书都是可信的但请确保您只调用受信任的站点

关于java - apache httpclient 使用 https 代理 : peer not authenticated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21973531/

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