Android Open Source Framework universal-image-loader loading HTTPS pictures

Source: Internet
Author: User

Solution is

Requires Android HTTPS httpsurlconnection this class ignores certificates

1, find Universal-image-loader the library dependency package below com.nostra13.universalimageloader.core.download below the Baseimagedownloader this class

Inside the CreateConnection this method, add the following:

1 protectedhttpurlconnection createconnection (String URL, Object extra)2             throwsIOException {3 4         Try {5 httpsurlconnection6. Setdefaulthostnameverifier (Newnullhostnameverifier ());7Sslcontext sc = sslcontext.getinstance ("TLS");8Sc.init (NULL, Trustallcerts,Newsecurerandom ());9 httpsurlconnectionTen . Setdefaultsslsocketfactory (Sc.getsocketfactory ()); One}Catch(keymanagementexception e) { A e.printstacktrace (); -}Catch(nosuchalgorithmexception e) { - e.printstacktrace (); the         } -  -String Encodedurl =uri.encode (URL, allowed_uri_chars); -HttpURLConnection conn = (httpurlconnection)NewURL (Encodedurl) + . OpenConnection (); - conn.setconnecttimeout (connecttimeout); + conn.setreadtimeout (readtimeout); A         returnConn; at}

1  Public classNullhostnameverifierImplementsHostnameverifier {2 3 @Override4          Public BooleanVerify (String hostname, sslsession session) {5LOG.I ("Restutilimpl", "Approving certificate for" +hostname);6             return true;7         }8 9}

//Create A trust manager that does not validate certificate chainstrustmanager[] Trustallcerts =NewTrustmanager[] {NewX509trustmanager () { Publicx509certificate[] Getacceptedissuers () {return NULL; }         Public voidcheckclienttrusted (x509certificate[] certs, String authtype) {} Public voidcheckservertrusted (x509certificate[] certs, String authtype) {} }};

Reference Blog: http://blog.csdn.net/a102111/article/details/44311059

Need to change the jar package directly: http://download.csdn.net/detail/yang7162082/8915429

  

Android Open Source Framework universal-image-loader loading HTTPS pictures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.