Code example for HttpsURLConnection

Methods: setHostnameVerifiersetSSLSocketFactory

            // Install hostname verifiers and trust managers that don't do 
            // anything in order to get around the client not trusting 
            // the test server due to a lack of certificates. 
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            connection.setHostnameVerifier(new TestHostnameVerifier());
            SSLContext context = SSLContext.getInstance("TLS");
            TestTrustManager trustManager = new TestTrustManager();
            context.init(null, new TestTrustManager[] {trustManager}, null);
            return connection;
        } else { 
            return url.openConnection();
     * {@link X509TrustManager} that trusts everybody. This is used so that