Ignore certificate errors when requesting a URL in Java

后端 未结 5 1993
一个人的身影
一个人的身影 2020-12-19 23:35

I\'m trying to print a URL (without having a browser involved at all) but the URL is currently throwing the following:

javax.net.ssl.SSLHandshakeException: 
         


        
5条回答
  •  轮回少年
    2020-12-20 00:28

    Extend JEditorPane to override the getStream() method.

    Inside that method, you can open a URLConnection. Test whether it is an HttpsURLConnection. If it is, initialize your own SSLContext with a custom X509TrustManager that doesn't perform any checks. Get the context's SSLSocketFactory and set it as the socket factory for the connection. Then return the InputStream from the connection.

    This will defeat any attempts by the runtime to protect the user from a spoof site serving up malware. If that's really what you want…

提交回复
热议问题