当前位置: 代码迷 >> J2SE >> HttpsURLConnection https:// 时好时错误!什么情况
  详细解决方案

HttpsURLConnection https:// 时好时错误!什么情况

热度:3061   发布时间:2013-02-25 00:00:00
HttpsURLConnection https:// 时好时异常!什么情况
Java code
 public static Image GetCodeImage() throws IOException  {                   try {                          Image img;            String urlStr = "https://login.sina.com.cn/cgi/pin.php?r=46111694";            URL url = new URL(urlStr);            HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection();   //打开网站链接s            urlConn.setRequestMethod("GET");                                    img = ImageIO.read(urlConn.getInputStream());                        String cookie = urlConn.getHeaderField("set-cookie");            System.out.println(cookie);                        return img;                    } catch (MalformedURLException ex) {            Logger.getLogger(SinaBlog.class.getName()).log(Level.SEVERE, null, ex);        }          return null;     }


  

run:
2012-8-10 12:28:03 com.from.Frame1 jButton5ActionPerformed
严重: null
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 com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1591)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:187)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:181)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1035)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:124)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:516)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:454)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:884)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1096)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1123)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1107)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:415)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:979)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
at com.net.post.SinaBlog.GetCodeImage(SinaBlog.java:34)
at com.from.Frame1.RunTaskCall(Frame1.java:359)
at com.from.Frame1.jButton5ActionPerformed(Frame1.java:383)
at com.from.Frame1.access$200(Frame1.java:23)
at com.from.Frame1$4.actionPerformed(Frame1.java:197)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6134)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5899)
at java.awt.Container.processEvent(Container.java:2023)
at java.awt.Component.dispatchEventImpl(Component.java:4501)
at java.awt.Container.dispatchEventImpl(Container.java:2081)
at java.awt.Component.dispatchEvent(Component.java:4331)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4301)
  相关解决方案