Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore SSL certificate errors in Apache HttpClient 4.0

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

like image 316
Viet Avatar asked Apr 24 '10 03:04

Viet


People also ask

How do I skip https?

To bypass SSL certificate validation for local and test servers, you can pass the -k or --insecure option to the Curl command. This option explicitly tells Curl to perform "insecure" SSL connections and file transfers. Curl will ignore any security warnings about an invalid SSL certificate and accept it as valid.

How do you skip the SSL handshake in RestTemplate?

To skip or avoid the SSL check, we need to modify the default RestTemplate available with the normal Spring package. In this configuration class, we basically declare a new Bean that creates a HTTPClient with the certificate check as disabled.


1 Answers

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(new AllowAllHostnameVerifier())     .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(); 
like image 61
erversteeg Avatar answered Sep 30 '22 16:09

erversteeg