Code example for HttpsURLConnection

Methods: disconnectgetInputStreamsetHostnameVerifier

0
 
    @Override protected void setUp() throws Exception { 
        URL url = new URL("https", host, "/");
        hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
        HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
        connection.setHostnameVerifier(new HostnameVerifier() {
            public boolean verify(String hostname, SSLSession sslSession) {
                try { 
                    encodedCertificates = certificatesToBytes(sslSession.getPeerCertificates());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                } 
                HostnameVerifierBenchmark.this.hostname = hostname;
                return true; 
            } 
        }); 
        connection.getInputStream();
        connection.disconnect();
    } 
 
    public void timeVerify(int reps) throws Exception {
        for (int i = 0; i < reps; i++) {
            final Certificate[] certificates = bytesToCertificates(encodedCertificates);
Stop searching for code, let great code find you!  Add Codota to your java IDE