Skip to content

Instantly share code, notes, and snippets.

@zjor
Created July 27, 2014 15:15
Show Gist options
  • Save zjor/a9a27bfeb99d446dc02f to your computer and use it in GitHub Desktop.
Save zjor/a9a27bfeb99d446dc02f to your computer and use it in GitHub Desktop.
Creates Apache HttpClient ignoring SSL. Version httpclient > 4.2.xx
SSLContextBuilder sslbuilder = new SSLContextBuilder();
sslbuilder.loadTrustMaterial(null,
new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
});
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslbuilder.build(),
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory> create()
.register("https", sslsf)
.register("http", new PlainConnectionSocketFactory())
.build();
CloseableHttpClient httpClient = HttpClientBuilder.create()
.setSSLSocketFactory(sslsf)
.setConnectionManager(new PoolingHttpClientConnectionManager(socketFactoryRegistry))
.build();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment