How to ignore SSL certificate errors in Apache HttpClient 4.0

Viet picture Viet · Apr 24, 2010 · Viewed 255.4k times · Source

How do I bypass invalid SSL certificate errors with Apache HttpClient 4.0?

Answer

erversteeg picture erversteeg · Jun 23, 2014

All of the other answers were either deprecated or didn't work for HttpClient 4.3.

Here is a way to allow all hostnames when building an http client.

CloseableHttpClient httpClient = HttpClients
    .custom()
    .setHostnameVerifier(AllowAllHostnameVerifier.INSTANCE)
    .build();

Or if you are using version 4.4 or later, the updated call looks like this:

CloseableHttpClient httpClient = HttpClients
    .custom()
    .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
    .build();