Created
July 27, 2014 15:15
-
-
Save zjor/a9a27bfeb99d446dc02f to your computer and use it in GitHub Desktop.
Creates Apache HttpClient ignoring SSL. Version httpclient > 4.2.xx
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
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