gpt4 book ai didi

java - Receiving Caused by : javax.net.ssl.SSLHandshakeException: 握手期间远程主机关闭连接

转载 作者:行者123 更新时间:2023-11-28 22:49:33 30 4
gpt4 key购买 nike

我收到 javax.net.ssl.SSLHandshakeException:当我尝试使用 Https 获取 Web 服务时,远程主机在握手异常期间关闭了连接

Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:946)
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:380)
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:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:220)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:164)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:139)
at com.cl.fwk.services.http.impl.WebServiceImpl.get(WebServiceImpl.java:241)
... 28 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(InputRecord.java:482)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
... 46 more

我的 HTTP 连接器配置:

   Connector connector = new Connector(Http11NioProtocol.class.getName());
Http11NioProtocol protocol = (Http11NioProtocol)
connector.getProtocolHandler();
protocol.setKeystoreFile("./Tests/Properties/keystore_local.ks");
protocol.setKeystorePass("changeit");
protocol.setSSLEnabled(true);
protocol.setSslProtocol("TLS"); // TLSv1
protocol.setClientAuth("true");
protocol.setMaxThreads(200);
protocol.setSecure(true);
connector.setPort(443);
protocol.setConnectionTimeout(30000);
tomcat.getService().addConnector(connector);

无论如何,我可以对我的代码做些什么来解决这个问题吗?这是完整的错误:

main, WRITE: TLSv1 Handshake, length = 48
main, received EOFException: error
main, handling exception: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
%% Invalidated: [Session-2, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]
main, SEND TLSv1 ALERT: fatal, description = handshake_failure
main, WRITE: TLSv1 Alert, length = 32
main, called closeSocket()

最佳答案

那是安全协议(protocol)的问题。您使用的是 TLSv1,但主机仅接受 TLSv1.1 和 TLSv1.2,那么您必须按照以下说明更改 Java 中的协议(protocol):

protocol.setProperty("https.protocols", "TLSv1.1");

关于java - Receiving Caused by : javax.net.ssl.SSLHandshakeException: 握手期间远程主机关闭连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44808088/

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