gpt4 book ai didi

java - 使用jsoup连接到不受信任的证书

转载 作者:行者123 更新时间:2023-12-02 10:38:49 26 4
gpt4 key购买 nike

我的 java 应用程序遇到问题。我使用 JSOUP 连接到一个网站,以前是 http,现在已移至 https。现在,当我运行该应用程序时,出现以下错误,有人能帮忙解决这个问题吗?

Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(Unknown Source)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
at java.security.cert.CertPathBuilder.build(Unknown Source)
... 32 more
javax.net.ssl.SSLHandshakeException: 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.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source)

最佳答案

如果您信任该站点,则可以通过将其设置为 true 来忽略 http 错误:

Document doc = Jsoup.connect("your_url").ignoreHttpErrors(true).get();

要忽略 TSL 验证,请设置 validateTLSCertificates(false):

Document doc = Jsoup.connect("your_url").validateTLSCertificates(false).get();

编辑

这个答案已经过时,因为 JSoup 已弃用并删除了版本 1.12.1 中的 validateTLSCertificates 方法

(https://jsoup.org/news/release-1.12.1)。

如果您信任有问题的网站并希望忽略 TLS 验证,请查看此答案 how-to-resolve-jsoup-error-unable-to-find-valid-certification-path

关于java - 使用jsoup连接到不受信任的证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53081118/

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