0
URL oauth = new URL(URL);
URLConnection oauth_connection = oauth.openConnection();

BufferedReader in = new BufferedReader(new InputStreamReader(
            oauth_connection.getInputStream()));

String inputLine = "";

String line;

//System.out.println(in.readLine());
while((line = in.readLine()) != null)
    inputLine += line;

in.close();

BufferedReader在该行引发异常:

线程“主”javax.net.ssl.SSLHandshakeException 中的异常:sun.security.validator.ValidatorException:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法在 sun.security 中找到请求目标的有效证书路径.ssl.Alerts.getSSLException(Unknown Source) at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source) at sun.security.ssl.Handshaker.fatalSE(Unknown Source) at sun.security.ssl.Handshaker.fatalSE(Unknown源) 在 sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source) 在 sun.security.ssl.ClientHandshaker.processMessage(Unknown Source) 在 sun.security.ssl.Handshaker.processLoop(Unknown Source) 在 sun.security.ssl sun.security.ssl.SSLSocketImpl 的 .Handshaker.process_record(未知来源)。readRecord(Unknown Source) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at sun。 net.www.protocol.https.HttpsClient.afterConnect(Unknown Source) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source ) 在 sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) 的 HttpsClient.afterConnect(Unknown Source) sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) sun.net.www。协议.https.HttpsURLConnectionImpl.getInputStream(未知来源)sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) 的 HttpsClient.afterConnect(Unknown Source) sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) sun.net.www。协议.https.HttpsURLConnectionImpl.getInputStream(未知来源)

4

2 回答 2

1

您可能拥有自签名证书或链式证书,其中链的某些部分不受信任。

您可以将证书导入您的信任库,请参阅数字证书:如何将 .cer 文件导入到 .truststore 文件中?

或者您可以忽略此问题,如在 Java 中请求 URL 时忽略证书错误

于 2012-06-22T21:28:45.883 回答
0

如果您的客户端是用 Java 编写的,那么您需要做的就是将服务器证书添加到受信任的 Java 密钥库中。

请参阅此页面。 https://blogs.oracle.com/gc/entry/unable_to_find_valid_certification

于 2012-06-22T21:27:37.603 回答