我正在使用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)
我是否知道此错误与证书问题有关?因为我已经将证书添加到truststore。
答案 0 :(得分:1)
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
我是否知道此错误与证书问题有关?因为我已经将证书添加到truststore。
这不是证书的问题。您访问的服务器没有进行正确的TLS握手。
我正在使用httpclient 4.5.2来调用代理服务器。
HTTP代理服务器上的HTTPS以纯文本HTTP CONNECT请求开始,然后建立隧道。只有在建立此隧道后,才能与原始目标服务器完成TLS握手。