Code example for HttpsURLConnection

Methods: getResponseCode

0
            { 
                // UNTRUSTED CERTIFICATE + DEFAULT SSL_SOCKET_FACTORY : MUST RAISE AN SSL EXCEPTION 
                URL url = new URL(sslUrlWithUntrustedCertificate);
                HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
                try { 
                    connection.getResponseCode();
                    fail("an exception should have been raised");
                } catch (SSLHandshakeException e) {
                    // ok 
                } 
            } 
             
            // register the AcceptAllSslSocketFactory 
            new AcceptAllSslSocketFactoryPlainJavaConfigurator(); 
             
            { 
                // UNTRUSTED CERTIFICATE + ACCEPT_ALL SSL_SOCKET_FACTORY : OK 
                URL url = new URL(sslUrlWithUntrustedCertificate);
                HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();