The problem is that the HTTPS server does not have a certificate, and it checks the web for a workaround:
Trusting all certificates using HttpClient over HTTPS
The main code is as follows:
Importjava.io.IOException;ImportJava.net.Socket;Importjava.net.UnknownHostException;Importjava.security.KeyManagementException;ImportJava.security.KeyStore;Importjava.security.KeyStoreException;Importjava.security.NoSuchAlgorithmException;Importjava.security.UnrecoverableKeyException;Importjava.security.cert.CertificateException;Importjava.security.cert.X509Certificate;ImportJavax.net.ssl.SSLContext;ImportJavax.net.ssl.TrustManager;ImportJavax.net.ssl.X509TrustManager;Importorg.apache.http.conn.ssl.SSLSocketFactory; Public classMysslsocketfactoryextendssslsocketfactory {sslcontext sslcontext= Sslcontext.getinstance ("TLS"); PublicMysslsocketfactory (KeyStore Truststore)throwsnosuchalgorithmexception, Keymanagementexception, Keystoreexception, unrecoverablekeyexception {Super(Truststore); TrustManager TM=NewX509trustmanager () { Public voidCheckclienttrusted (x509certificate[] chain, String authtype)throwscertificateexception {} Public voidCheckservertrusted (x509certificate[] chain, String authtype)throwscertificateexception {} Publicx509certificate[] Getacceptedissuers () {return NULL; } }; Sslcontext.init (NULL,NewTrustmanager[] {TM},NULL); } @Override PublicSocket Createsocket (socket socket, String host,intPortBooleanAutoClose)throwsIOException, unknownhostexception {returnsslcontext.getsocketfactory (). Createsocket (socket, host, port, AutoClose); } @Override PublicSocket Createsocket ()throwsIOException {returnsslcontext.getsocketfactory (). Createsocket (); }}
PublicHttpClient getnewhttpclient () {Try{KeyStore Truststore=keystore.getinstance (Keystore.getdefaulttype ()); Truststore.load (NULL,NULL); Sslsocketfactory SF=Newmysslsocketfactory (Truststore); Sf.sethostnameverifier (Sslsocketfactory.allow_all_hostname_verifier); Httpparams params=NewBasichttpparams (); Httpprotocolparams.setversion (params, httpversion.http_1_1); Httpprotocolparams.setcontentcharset (params, HTTP. UTF_8); Schemeregistry Registry=NewSchemeregistry (); Registry.register (NewScheme ("http", Plainsocketfactory.getsocketfactory (), 80)); Registry.register (NewScheme ("https", SF, 443)); Clientconnectionmanager CCM=NewThreadsafeclientconnmanager (params, registry); return Newdefaulthttpclient (CCM, params); } Catch(Exception e) {return Newdefaulthttpclient (); }}
Android-not Trusted Server Certificate exception