我正在尝试使用向“ https://api.ecs.echa.europa.eu ”发送 HttpRequest
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.ecs.echa.europa.eu"))
.GET()
.build();
HttpClient httpClient = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).build();
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
执行此代码我得到javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
现在我已经通过将证书添加到我的 java 信任库中找到了解决此问题的方法$JAVA_HOME/jre/lib/security/cacerts
我仍然不明白,为什么这是必要的:
特定网站 ( https://api.ecs.echa.europa.eu ) 使用根证书DigiCert Global Root CA,该证书已包含在 java 信任库中。为什么这还不够?
向使用此根证书的其他网站发送请求确实有效...
谢谢你的帮助 :)