Skip to content

Instantly share code, notes, and snippets.

@jiafangtao
Created June 25, 2018 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiafangtao/10d2567d8edf814bf952ca3e5620a070 to your computer and use it in GitHub Desktop.
Save jiafangtao/10d2567d8edf814bf952ca3e5620a070 to your computer and use it in GitHub Desktop.
HttpClient to ignore SSL errors
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