Java:HttpsUrlConnection-PKIX路径生成失败

Java:HttpsUrlConnection-PKIX路径生成失败,java,ssl,https,pkix,Java,Ssl,Https,Pkix,我试图用Java下载https url的内容,但什么时候会出现此错误 PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 我已经能够建立到其他安全服务的https连接,但不是我现在尝试使用的那个。服务器是我们内部的,并且有Godaddy证书。这可能是问题所

我试图用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)

如果证书无效,则会发生此异常。如果使用浏览器打开URL(Mozilla Firefox最适合此测试,IE和Chrome使用Windows域中Active Directory服务器的证书),证书是否显示为有效


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

您的猜测是正确的。这看起来像是GoDaddy还没来得及解决的问题。他们的SSL技术令人失望。