CloseableHttpClient client = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
is giving me an error of :
[sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target]
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
i.e. it is not adding all self-signed certificates as expected..
My HTTPClient version is 4.5.1 and HTTPCore is version 4.4.4
Please give me a solution without using deprecated methods like SSLContextBuilder
Try using this snippet:
import java.security.*;
import org.apache.http.conn.ssl.*;
try
{
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy() {
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException
{
return true;
}
}).build();
CloseableHttpClient client =HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(new NoopHostnameVerifier())
.build();
}
catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e)
{
e.printStackTrace();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With