Java: Disabling SSL checks for a given HttpClient

If you know what you are doing, you can disable the SSL trust and host name checks when using the HttpClient in Java. It goes like this:

TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public[] getAcceptedIssuers() {
return null;
public void checkClientTrusted([] certs, String authType) {
public void checkServerTrusted([] certs, String authType) {

SSLContext sslContext;
sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new;
SSLSocketFactory sslSocketFactory = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Scheme scheme = new Scheme("https", sslSocketFactory, 443);

This entry was posted in Java. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s