Created
June 25, 2018 07:42
-
-
Save jiafangtao/10d2567d8edf814bf952ca3e5620a070 to your computer and use it in GitHub Desktop.
HttpClient to ignore SSL errors
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
public static Client ignoreSSLClient() throws Exception { | |
SSLContext sslcontext = SSLContext.getInstance("TLS"); | |
sslcontext.init(null, new TrustManager[]{new X509TrustManager() { | |
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {} | |
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {} | |
public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } | |
}}, new java.security.SecureRandom()); | |
return ClientBuilder.newBuilder() | |
.sslContext(sslcontext) | |
.hostnameVerifier((s1, s2) -> true) | |
.build(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment