0

我正在尝试用 Java 下载 https url 的内容,但是什么时候会出现此错误。

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

我已经能够建立与其他安全服务的 https 连接,但不是我现在尝试访问的那个。该服务器是我们内部的,并具有 Godaddy 证书。这可能是问题吗?

public class DataRegressionTest {

    private static String urlString = "https://somedomain.com/GetData";

    public static void main(String[] args) throws Exception {
        URL url = new URL(urlString);
        HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
        String urlContent = StreamUtils.urlConnectionToUrlContent(httpsURLConnection);
        JsonNode jsonNode = JsonUtils.jsonToTree(urlContent);
        System.out.println(jsonNode);
    }
}

我该如何解决?

这是更完整的堆栈跟踪

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1884)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:276)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:270)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1341)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1016)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1300)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
4

1 回答 1

1

如果证书无效,则会发生此异常。如果您使用浏览器打开 URL(Mozilla Firefox 将是此测试的最佳选择,IE 和 Chrome 使用 Windows 域中 Active Directory 服务器的证书)它显示的证书有效吗?

如果不是(我猜),您将不得不下载证书并将其添加到 JVM。

于 2013-12-06T23:16:55.520 回答