簡體   English   中英

Java:HttpsUrlConnection-PKIX路徑構建失敗

[英]Java: HttpsUrlConnection - PKIX path building failed

我正在嘗試用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。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM