首页 > 编程语言 > 详细

java使用jsoup时绕过https证书验证

时间:2021-06-05 11:32:51      阅读:26      评论:0      收藏:0      [点我收藏+]

详细错误信息:

SunCertPathBuilderException: unable to find valid certification path to requested target

问题原因:
爬相关数据,因该网站有SSL加密,故无法爬取。

问题解决之核心代码:

/**
    * 绕过HTTPS验证
    */
   static public void initTSL() {
       try {
           SSLContext context = SSLContext.getInstance("TLS");
           context.init(null, new X509TrustManager[]{new X509TrustManager() {
               @Override
               public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
               }

               @Override
               public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
               }

               @Override
               public X509Certificate[] getAcceptedIssuers() {
                   return new X509Certificate[0];
               }
           }}, new SecureRandom());
           HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
       } catch (NoSuchAlgorithmException e) {
       } catch (KeyManagementException e) {
       }
   }

 

java使用jsoup时绕过https证书验证

原文:https://www.cnblogs.com/youcong/p/14851649.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!