Jsoup 解决 PKIX path building failed

今天同事说人行征信改版了,让帮忙看看,确实加了ActiveX控件,于是想当然的先写个简单的测试类:

Jsoup.connect("https://ipcrs.pbccrc.org.cn/page/login/loginreg.jsp")
                .method(Connection.Method.GET)
                .execute();

结果没想到运行之后直接报错:

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
 at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)
 at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
 at sun.security.validator.Validator.validate(Validator.java:260)
 at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
 at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
 at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
 at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1496)
 ... 14 more

解决方案:

.validateTLSCertificates(false)//加入此方法即可,忽略 TSL 验证设置

完整请求代码:

Jsoup.connect("https://ipcrs.pbccrc.org.cn/page/login/loginreg.jsp")
        .method(Connection.Method.GET)
        .validateTLSCertificates(false)//忽略 TSL 验证设置
        .execute();

未经允许不得转载:鹞之神乐 » Jsoup 解决 PKIX path building failed

赞 (0) 打赏

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏