private static void trustAllHosts ( ) { // Create a trust manager that does not validate certificate chains TrustManager [ ] trustAllCerts = new TrustManager [ ] { new X509TrustManager ( ) { @ Override public java . security . cert . X509Certificate [ ] getAcceptedIssuers ( ) { return new java . security . cert . X509Certificate [ ] { } ; } @ Override public void checkClientTrusted ( X509Certificate [ ] chain , String authType ) throws CertificateException { } @ Override public void checkServerTrusted ( X509Certificate [ ] chain , String authType ) throws CertificateException { } } } ; // Install the all-trusting trust manager try { SSLContext sc = SSLContext . getInstance ( "TLS" ) ; sc . init ( null , trustAllCerts , new java . security . SecureRandom ( ) ) ; HttpsURLConnection . setDefaultSSLSocketFactory ( sc . getSocketFactory ( ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } }
Trust every server - dont check for any certificate