2012-06-22 155 views
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行抛出异常:发送HTTP请求到服务器都异常时有发生

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

+0

但一半的时候,它给结果返回成功 –

回答

1

您可能要么有自签名证书,要么链接的某些部分不可信。

您可以将证书导入您的信赖店看到Digital Certificate: How to import .cer file in to .truststore file using?

或者你可以忽略的问题,因为在这个问题Ignore certificate errors when requesting a URL in Java

+0

但有一半时间成功返回 –

+0

也许您正在碰到一个负载均衡器,该负载均衡器依赖于证书的服务器,而不是拥有自己的服务器,并且平衡器后面的服务器之一出现故障或者您还需要在信任库中安装不同的证书? – digitaljoel

+0

但关闭一台服务器后,仍然有这个问题,一半和一半。 –

相关问题