2015-11-14 196 views
0

当发送GET请求来www.sunnyportal.com错误代码出现在控制台中,如下:Get请求handshake_faliure:javax.net.ssl.SSLHandshakeException

javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) 
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154) 
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1979) 
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1086) 
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332) 
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359) 
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343) 
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:1301) 
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254) 
at personal.Project.GetUrl.getReq(GetUrl.java:25) 
at personal.Project.GetUrl.main(GetUrl.java:34) 

我尝试以下页面没有运气:

+ Received fatal alert: handshake_failure through SSLHandshakeException

+ How to solve javax.net.ssl.SSLHandshakeException Error?

这里是我的代码:

package personal.Project; 

    import java.io.IOException; 

    import java.io.InputStream; 

    import java.net.MalformedURLException; 

    import java.net.URL; 

    import java.net.URLConnection; 

    import java.net.URLEncoder; 

    public class GetUrl { 

     private String url = "https://www.sunnyportal.com/Templates/ChartValues.aspx"; 

private String charset = "UTF-8"; // Or in Java 7 and later, use the constant: java.nio.charset.StandardCharsets.UTF_8.name() 
private String login = "<>"; 
private String password = "<>"; 

public String getReq() throws MalformedURLException, IOException 
{ 
    String query = String.format("login=%s&password=%s", 

      URLEncoder.encode(login, charset), 
      URLEncoder.encode(password, charset)); 

     URLConnection c = new URL(url + "?" + query).openConnection(); 
     c.setRequestProperty("Accept-Charset", charset); 
     InputStream response = c.getInputStream(); 

     return response.toString(); 
} 
public static void main (String args[]) 
{ 
    GetUrl data = new GetUrl(); 
    String getString = null; 
    try { 
     getString = data.getReq(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
     System.exit(1); 
    } 

    System.out.println(getString); 
} 

} 

会很乐意帮助解决这个问题,提前致谢!

回答

2

根据https://www.ssllabs.com/ssltest/analyze.html?d=sunnyportal.com该服务器只协商一个密码组TLS_RSA_WITH_AES_256_CBC_SHA,它使用AES和256位密钥。

如果您正在使用甲骨文的Java使用任何对称密码超过128位,其中包括AES 256,你必须下载并安装JCE无限强度仲裁策略文件的版本。对于当前支持的版本8,在通用下载页面底部附近http://www.oracle.com/technetwork/java/javase/downloads/index.html它链接到http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html。对于旧版本搜索,发现http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.htmlhttp://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html

PS:暗示SSLHandshakeException while connecting to a https site,虽然我不确定你是否可以预料到会发现。

+0

现在我有文件是有一个特定的文件夹,我必须把它放进去?或者我刚刚起来并运行它? –

+0

@PeterSparks你解压缩它(在现代Windows资源管理器中打开的是这样做的),并把两个jar放到你的JRE的'lib/security'目录中,替换'受限'的目录。您的JRE的位置因您的平台和(通常)您的安装方式而有很大差异,您不会这么说。在zip中还有一个README文件,试图解释这一点,但仍然没有涵盖所有可能的情况。 –