我正在运行一个小主(在Java 8,版本1.8.0.112中)尝试向“ https ”网址执行HTTP请求,我们称之为“original_url”。我正在使用标准的CloseableHttpClient,以这种方式创建它:
CloseableHttpClient httpClient = HttpClientBuilder.create()
.setConnectionManager(new PoolingHttpClientConnectionManager())
.setDefaultRequestConfig(RequestConfig.DEFAULT)
.build();
但是当我点击时:
httpClient.execute(request);
我收到了这个错误:
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
(Full stacktrace bellow)
奇怪的是,当我从相同的java代码到达不同的“https”网址时,它可以正常工作。此外,当我从Chrome或Postman(REST客户端)到达“original_url”时,我成功达到了它。我也尝试从php代码执行对“original_url”的http调用,它运行正常。
我在StackOverflow中寻找了很多答案,都试图将HttpClient设置为忽略未知证书,但它没有用。此外,该网站的证书似乎没有过期,因为我可以从Chrome / Postman / php代码访问“original_url”网站。
是否存在JVM密钥库存在问题?任何帮助将不胜感激。
以下是完整的异常堆栈跟踪:
Exception in thread "main" javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2023)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1125)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
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:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at com.taboola.jobs.crawler.geoedge.RestAdapterBuilder.main(RestAdapterBuilder.java:127)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)