我正在使用 httpclient 4.5.2 调用代理服务器。
HttpHost proxy = new HttpHost(proxyHost, proxyPort, https);
HttpHost target = new HttpHost(ip, 443, "https");
HttpPost httppost = new HttpPost(url);
CloseableHttpResponse response = httpclient.execute(target, httppost );
下面是我得到的错误:-
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at sun.security.ssl.InputRecord.handleUnknownRecord(InputRecord.java:671)
at sun.security.ssl.InputRecord.read(InputRecord.java:504)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:388)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:117)
我可以知道这个错误与证书问题有关吗?因为我已经将证书添加到信任库。
最佳答案
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
May I know this error is related to cert problem? Because I already add the cert to truststore.
这不是证书的问题。您访问的服务器没有进行正确的 TLS 握手。
I am using httpclient 4.5.2 to call proxy server.
HTTP 代理服务器上的 HTTPS 以纯文本 HTTP CONNECT 请求开始,然后建立隧道。只有在建立此隧道后,才会与原始目标服务器完成 TLS 握手。
关于ssl - HttpClient 4.5.2 - SSL 证书问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40465800/