Answer the question
In order to leave comments, you need to log in
Why is the connection to the web server via HTTPS successful even without HostnameVerifier?
There is a simple Java client code that connects to a web server. Previously, without the following "poultice", the HTTPS connection failed due to a forgot-what-exception, similar to running curl without the "-k" option:
// не для продакшна!
X509TrustManager[] DUMMY_TRUST_MANAGERS = {
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() { return null; }
public void checkClientTrusted(X509Certificate[] certs, String authType) { }
public void checkServerTrusted(X509Certificate[] certs, String authType) { }
}
}
sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, DUMMY_TRUST_MANAGERS, new SecureRandom());
connection.setSSLSocketFactory(sslContext.getSocketFactory())
connection.setHostnameVerifier(new HostnameVerifier {
public boolean verify(String host, SSLSession sslSession) {
return true
}
})
URL url = new URL(args[0]);
HttpsURLConnection c = (HttpsURLConnection)url.openConnection();
c.setDoOutput(false);
c.setDoInput(true);
c.connect();
c.getResponseCode();
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question