HttpURLConnection - “https://” vs. “http://”

后端 未结 6 1803
无人及你
无人及你 2020-12-29 13:15

I\'m trying to get the favicon of the url the user enters, for example

_url = \"google.com\";

I use HttpUrlConnection to get the Bitmap of

6条回答
  •  孤独总比滥情好
    2020-12-29 13:48

    Try this when URL start with "https":

                  TrustManager[] trustAllCerts = new TrustManager[]
                   {
                     new X509TrustManager()
                      {
                        public java.security.cert.X509Certificate[] getAcceptedIssuers()  { return null; }
                        public void checkClientTrusted( java.security.cert.X509Certificate[] certs, String authType)  {}
                        public void checkServerTrusted( java.security.cert.X509Certificate[] certs, String authType)  {}
                      }
                     };
                  try
                    {
                      SSLContext sc = SSLContext.getInstance( "SSL"); // "TLS" "SSL"
                      sc.init( null, trustAllCerts, null);
                      HttpsURLConnection.setDefaultSSLSocketFactory( sc.getSocketFactory());
                      HttpsURLConnection.setDefaultHostnameVerifier( 
                       new HostnameVerifier() 
                        {
                          public boolean verify( String hostname, SSLSession session) { return true; }
                        } );
                    }
                   catch( Exception e)
    

提交回复
热议问题