我正在尝试使用]将HttpRequest发送到“ https://api.ecs.echa.europa.eu”
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_HOME/jre/lib/security/cacerts
下的Java信任库中找到了解决此问题的方法>
我仍然不明白,为什么这是必要的:
特定网站(https://api.ecs.echa.europa.eu)使用根证书DigiCert全球根CA
,该证书已经包含在java truststore中。为什么还不够?向使用此根证书的其他网站发送请求确实有效...
感谢您的帮助:)
[我正在尝试使用HttpRequest request = HttpRequest.newBuilder().uri(URI.create(“ https://api.ecs来将HttpRequest发送到” https://api.ecs.echa.europa.eu“ .echa.europa.eu“))...
之所以可能发生此错误,是因为服务器配置错误。您可以在此处查看:https://whatsmychaincert.com/?api.ecs.echa.europa.eu
此站点将告诉您服务器证书链是否配置正确,似乎并非如此。