PKIX: unable to find valid certification path to requested target

时间:2023-03-09 18:02:00
PKIX: unable to find valid certification path to requested target
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
} public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
} public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
}
}; try {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, trustAllCerts, new java.security.SecureRandom());
// ... 使用 context 获取 SSLSocketFactory
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e);
} catch (KeyManagementException e) {
throw new IllegalStateException(e);
}