简体   繁体   English

获取异常 javax.net.ssl.SSLHandshakeException:收到致命警报:protocol_version

[英]Getting an exception javax.net.ssl.SSLHandshakeException: Received fatal alert: protocol_version

I have created a webcrawler, that will return the page for a URL.我创建了一个网络爬虫,它将返回一个 URL 的页面。 For some URLs I get : javax.net.ssl.SSLHandshakeException: Received fatal alert: protocol_version对于我得到的一些 URL:javax.net.ssl.SSLHandshakeException: Received fatal alert: protocol_version

The purpose of this is just to parse the webpage returned.这样做的目的只是解析返回的网页。 So I am looking at ways to bypass.所以我正在寻找绕过的方法。 The SSL verification SSL验证

 (s, sslSession) -> true

So I create a SSLConnectionSocketFactory所以我创建了一个 SSLConnectionSocketFactory

private SSLConnectionSocketFactory sslFactory() {
             SSLContext sslcontext = null;
             try {
                    sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build();

             } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
             }
              SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslcontext, (s, sslSession) -> true);

             return sslConnectionSocketFactory;
       }

And then add it to the HTMLClient然后将其添加到 HTMLClient

var clientBuilder  = HttpClientBuilder.create()
        .setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build())
                .setRedirectStrategy(new LaxRedirectStrategy())
                .setDefaultCookieStore(cookieStore)
                .setSSLSocketFactory(sslFactory());

According to what I have researched this should bypass SSL verification, but it still throws the exception.根据我的研究,这应该绕过 SSL 验证,但它仍然抛出异常。 I am using httpclient-4.5.13.我正在使用 httpclient-4.5.13。

I understand the security implications, but this is parsing a webpage, it will not be sending any data.我了解安全隐患,但这是解析网页,它不会发送任何数据。 Thanks for any help.谢谢你的帮助。

Ok this works with httpclient-4.5.13 java 11, it wont work with Java 16. So set trusted certificates.好的,这适用于 httpclient-4.5.13 java 11,它不适用于 Java 16。所以设置可信证书。

private SSLContext SSLConnection() throws NoSuchAlgorithmException, KeyManagementException {
        TrustManager[] trustAllCerts = new TrustManager[] {
                   new X509TrustManager() {
                      public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                        return null;
                      }
                      public void checkClientTrusted(X509Certificate[] certs, String authType) {  }
                      public void checkServerTrusted(X509Certificate[] certs, String authType) {  }
                   }
                };
                SSLContext sc = SSLContext.getInstance("SSL");
                sc.init(null, trustAllCerts, new java.security.SecureRandom());
                return sc;
    }

And add it to clientBuilder并将其添加到 clientBuilder

 var clientBuilder  = HttpClientBuilder.create()
                 .setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build())
                    .setRedirectStrategy(new LaxRedirectStrategy())
                    .setDefaultCookieStore(cookieStore)
                    .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
                    .setSSLContext(SSLConnection());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取 javax.net.ssl.SSLHandshakeException:收到致命警报:使用 jmeter 运行时来自 API 响应的协议版本 - Getting javax.net.ssl.SSLHandshakeException: Received fatal alert: protocol_version from API response while running using jmeter SSL异常:javax.net.ssl.SSLHandshakeException:收到致命警报:certificate_unknown - SSL Exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate_unknown Android Studio 抛出“线程“main”中的异常 javax.net.ssl.SSLException:收到致命警报:protocol_version” - Android Studio throwing "Exception in thread "main" javax.net.ssl.SSLException: Received fatal alert: protocol_version" 获取 javax.net.ssl.SSLException:在使用 Jsoup 抓取数据时收到致命警报:protocol_version - getting javax.net.ssl.SSLException: Received fatal alert: protocol_version while scraping data using Jsoup 调用 Web 服务:javax.net.ssl.SSLException:收到致命警报:protocol_version - Calling web service: javax.net.ssl.SSLException: Received fatal alert: protocol_version javax.net.ssl.SSLException:收到致命警报:协议版本 - javax.net.ssl.SSLException: Received fatal alert: protocol_version javax.net.ssl.SSLException:收到致命警报:Selenium的protocol_version - javax.net.ssl.SSLException: Received fatal alert: protocol_version with Selenium java7中如何处理异常“ javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure” - how to handle exception “javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure” in java7 获取javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure错误 - Getting javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure Error 获取 javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure - Getting javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM