Volley support HTTPS, but the framework is not added to the default, you can modify a small number of source code to achieve;
One is to override the third construct of the Volley.java Newrequestqueueindisk method call. And because these three constructs last called the one with the most parameters, the Sslsocketfactory instance can also be generated directly by default in the third construct.
The second is to add the Httpstrustmanager class in Toolbox (on the Code) and make minor changes to the Hurlstack Createconnetcion method.
PackageCom.android.volley.toolbox;Importjava.security.KeyManagementException;Importjava.security.NoSuchAlgorithmException;ImportJava.security.SecureRandom;Importjava.security.cert.X509Certificate;ImportJavax.net.ssl.HostnameVerifier;Importjavax.net.ssl.HttpsURLConnection;ImportJavax.net.ssl.SSLContext;Importjavax.net.ssl.SSLSession;ImportJavax.net.ssl.TrustManager;ImportJavax.net.ssl.X509TrustManager; Public classHttpstrustmanagerImplementsX509trustmanager {Private Statictrustmanager[] trustmanagers; Private Static Finalx509certificate[] _acceptedissuers =Newx509certificate[] {}; @Override Public voidcheckclienttrusted (java.security.cert.x509certificate[] x509certificates, String s)throwsjava.security.cert.CertificateException {//To change body of implemented methods use File | Settings | File//Templates.} @Override Public voidcheckservertrusted (java.security.cert.x509certificate[] x509certificates, String s)throwsjava.security.cert.CertificateException {//To change body of implemented methods use File | Settings | File//Templates. } Public Booleanisclienttrusted (x509certificate[] chain) {return true; } Public Booleanisservertrusted (x509certificate[] chain) {return true; } @Override Publicx509certificate[] Getacceptedissuers () {return_acceptedissuers; } Public Static voidAllowallssl () {Httpsurlconnection.setdefaulthostnameverifier (NewHostnameverifier () {@Override Public BooleanVerify (String arg0, sslsession arg1) {//TODO auto-generated Method Stub return true; } }); Sslcontext Context=NULL; if(Trustmanagers = =NULL) {trustmanagers=NewTrustmanager[] {NewHttpstrustmanager ()}; } Try{Context= Sslcontext.getinstance ("TLS"); Context.init (NULL, Trustmanagers,Newsecurerandom ()); } Catch(nosuchalgorithmexception e) {e.printstacktrace (); } Catch(keymanagementexception e) {e.printstacktrace (); } httpsurlconnection.setdefaultsslsocketfactory (context. Getsocketfactory ()); }}
protected throws IOException { if("https". Equals (Url.getprotocol (). toLowerCase ())) { Httpstrustmanager.allowallowssl (); } return (HttpURLConnection) url.openconnection ();}
Third, each time volleyqueue before the Httpstrustmanager.allowallowssl ();
Httpstrustmanager.allowallowssl (); Mvolleyquene.add (Newrequest ());
The default is in the second type.
Volley adding HTTPS support