如果直接用HttpClient发送https请求的时候报错:
sun.security.validator.ValidatorException:PKIXpathbuildingfailed:sun.security.provider.certpath.SunCertPathBuilderException:unabletofindvalidcertificationpathtorequestedtarget.
一般有以下两种方式解决解决这个问题。
1.绕开校验环节,重写相关实现类
public static CloseableHttpClient getClient() {
SSLContext sslContext = null;
try {
sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
// 信任所有
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}).build();
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(VerfiyCodeUtils.class.getName()).log(Level.SEVERE, null, ex);
} catch (KeyStoreException ex) {
Logger.getLogger(VerfiyCodeUtils.class.getName()).log(Level.SEVERE, nu