Code example for HttpsURLConnection

Methods: connect, disconnect, getResponseMessage, setHostnameVerifier

0
 
        URL url = new URL("https://localhost:" + address.getPort() + "/");
        System.out.println("trying to connect to " + url + "...");
 
        HttpsURLConnection uc = (HttpsURLConnection) url.openConnection();
        uc.setHostnameVerifier(new AllHostnameVerifier());
        if (uc instanceof javax.net.ssl.HttpsURLConnection) {
            ((javax.net.ssl.HttpsURLConnection) uc).setSSLSocketFactory(new SimpleSSLSocketFactory());
            System.out.println("Using TestSocketFactory");
        } 
        uc.connect();
        System.out.println("CONNECTED " + uc);
        System.out.println(uc.getResponseMessage());
        uc.disconnect();
    } 
 
    /** 
     * Https Server 
     */ 
    public void startHttpsServer() throws IOException, NoSuchAlgorithmException  { 
        httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);