问题描述
我正在使用 JSoup 来获取网站.
I am using JSoup to fetch websites.
我用这一行进行提取:
Document doc = Jsoup.connect(urlString).get();
该代码在首次运行程序的每个实例时都可以正常运行.如果再进行另一次提取,最终会出现以下错误:
The code works fine the first time it is run each instance of my program. If I then do another fetch, I eventually get the following error:
javax.net.ssl.SSLHandshakeException: No subject alternative DNS name matching <domain> found.
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:128)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:321)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:259)
at java.base/sun.security.ssl.CertificateMessage$T13CertificateConsumer.checkServerCerts(CertificateMessage.java:1329)
at java.base/sun.security.ssl.CertificateMessage$T13CertificateConsumer.onConsumeCertificate(CertificateMessage.java:1204)
at java.base/sun.security.ssl.CertificateMessage$T13CertificateConsumer.consume(CertificateMessage.java:1151)
at java.base/sun.security.ssl.SSLHandshake.consume(SSLHandshake.java:392)
at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:444)
at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:421)
at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:178)
at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:164)
at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1152)
at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1063)
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:402)
at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:567)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:163)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:730)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:706)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:299)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:288)
at net.joshuad.novaprice.scrapers.Scraper.getSellPrice(Scraper.java:149)
at net.joshuad.novaprice.mtg.Pricer.getSellPrices(Pricer.java:20)
at net.joshuad.novaprice.MainPanel.lambda$6(MainPanel.java:271)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.security.cert.CertificateException: No subject alternative DNS name matching starcitygames.com found.
at java.base/sun.security.util.HostnameChecker.matchDNS(HostnameChecker.java:207)
at java.base/sun.security.util.HostnameChecker.match(HostnameChecker.java:98)
at java.base/sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:459)
at java.base/sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:434)
at java.base/sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:233)
at java.base/sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:129)
at java.base/sun.security.ssl.CertificateMessage$T13CertificateConsumer.checkServerCerts(CertificateMessage.java:1313)
... 21 more
有时我只能运行一次提取.有时我可以运行三到四次.但最终它失败,并出现上述错误.一旦失败,它总是失败,直到重新启动JVM和我的程序.如果我重新启动JVM和程序,则它将再次运行.
Sometimes I can run the fetch only once. Sometimes I can run it three or four times. But eventually it fails with the above error. Once it fails, it always fails until the JVM and my program are restarted. If I restart the JVM and program, it then works again.
我尝试引入时间延迟,以查看问题是否是发出的请求过快,但这似乎并没有改变任何东西.我能够成功发出1-4个请求,然后情况变糟,直到重新启动程序为止.请求之间有多少时间延迟都没有关系.一旦以这种方式失败一次,它将继续失败,直到我重新启动程序.
I have tried introducing time delays to see if the issue is requests made too quickly, but that doesn't seem to change anything. I'm able to make 1-4 requests successfully, then things go sour until I restart the program. It doesn't matter how much time delay there is between requests. Once it has failed once in this way, it will continue to fail until I restart the program.
我的程序没有保留任何缓存的信息.我要做的就是获取URL上的内容,对其进行读取和处理,然后将其显示给用户.每个新的获取(就我的程序而言)都是一个独立的事务.
My program is not keeping any cached information. All I do is fetch the content at the URL, read it and process it, then display it to the user. Each new fetch is (as far as my program is concerned) an independent transaction.
我的程序格式很简单.基本上是这样:
My program is pretty simple in format. It's basically:
//Build the UI
//Wait for User Search Input
//Figure out the URL for the user's request
Document doc = Jsoup.connect(urlString).get();
//Process the data, display it to the user
//Repeat until window closed.
关于如何解决此问题的任何想法?
Any thoughts on how I can troubleshoot this one?
我正在Oracle Java JDK 11.0.1上运行它.
I am running this on Oracle Java JDK 11.0.1.
推荐答案
我能够通过从Java 11 SDK升级到Java 13 SDK来解决此问题.
I was able to fix this problem by upgrading from Java 11 SDK to Java 13 SDK.
我看到了一些建议,尝试将-Dcom.sun.jndi.ldap.object.disableEndpointIdentification=true
添加到jvm参数中,但这对我不起作用.
I saw recommendations to try adding -Dcom.sun.jndi.ldap.object.disableEndpointIdentification=true
to the jvm arguments, but that didn't work for me.
这篇关于JSoup javax.net.ssl.SSLHandshakeException:没有与< url>匹配的主题替代DNS名称.成立的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!