最近在请求https接口的时候,发生了异常:
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SuncertPathBuilderException: unable to find valid certification path to requested target
无法找到到请求目标的有效证书路径(据推测应该是服务端相关证书配置出现问题)
那么如何跳过SSL证书验证来发起https请求呢
try (
CloseableHttpClient client = HttpClients.custom()
.setSSLSocketFactory(
new SSLConnectionSocketFactory(SSLContextBuilder.create().loadTrustMaterial(TrustAllStrategy.INSTANCE).build()),
NoopHostnameVerifier.INSTANCE)
)
.build()
){
// 然后就可以使用client绕过SSL验证请求接口了
}
标签:请求,验证,sun,证书,SSL,跳过,httpclient From: https://www.cnblogs.com/ashet/p/17888265.html