我正在尝试用Java下载https url的内容,但是什么时候才会得到这个错误。
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target我已经能够连接到其他安全服务的https,但不是我现在试图点击的那个。服务器对我们来说是内部的,并且有一个Go爹地证书。这会是问题吗?
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)发布于 2013-12-06 23:16:55
如果证书无效,则发生此异常。如果您使用浏览器打开URL (Mozilla Firefox将是此测试的最佳选择,IE和Chrome将使用Windows域中Active Directory Server的证书),那么证书显示为有效吗?
如果没有(我猜),您将不得不下载证书并将其添加到JVM中。
https://stackoverflow.com/questions/20431880
复制相似问题