Forked from mingliangguo/disable_SSL_and_hostname_verification.java
Created
May 2, 2020 07:34
-
-
Save Artur-at-work/459ef90f8166f75d9ca1ead37a733063 to your computer and use it in GitHub Desktop.
disable SSL and host name verification for apache httpclient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
TrustManager[] trustAllCerts = new TrustManager[] { | |
new X509TrustManager() { | |
public java.security.cert.X509Certificate[] getAcceptedIssuers() { | |
return null; | |
} | |
public void checkClientTrusted(X509Certificate[] certs, String authType) { } | |
public void checkServerTrusted(X509Certificate[] certs, String authType) { } | |
} | |
}; | |
SSLContext sc = SSLContext.getInstance("SSL"); | |
sc.init(null, trustAllCerts, new SecureRandom()); | |
CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).setSslcontext(sc).build(); | |
String output = Executor.newInstance(httpClient).execute(Request.Get("https://127.0.0.1:3000/something") | |
.connectTimeout(1000) | |
.socketTimeout(1000)).returnContent().asString(); | |
} catch (Exception e) { | |
} | |
# source: http://stackoverflow.com/questions/2703161/how-to-ignore-ssl-certificate-errors-in-apache-httpclient-4-0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment