java - 获取请求handshake_failure :javax.net.ssl.SSLHandshakeException

标签 java handshake sslhandshakeexception

向www.sunnyportal.com发送get请求时,控制台出现错误代码,如下:

    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 );
}

}

希望得到帮助解决这个问题,提前致谢!

最佳答案

根据https://www.ssllabs.com/ssltest/analyze.html?d=sunnyportal.com该服务器仅协商一种密码套件 TLS_RSA_WITH_AES_256_CBC_SHA,该密码套件使用具有 256 位 key 的 AES。

如果您使用 Oracle Java 来使用 128 位以上的任何对称密码(包括 AES 256),则必须下载并安装 JCE Unlimited Strength 管辖策略文件你的版本。对于当前支持的版本 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的欺骗尽管我不确定您是否会发现这一点。

关于java - 获取请求handshake_failure :javax.net.ssl.SSLHandshakeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33711010/

相关文章:

java - 如何处理源代码中的巨大 SQL 字符串

java - 有没有办法在 JVM 中找到加载的类文件?

java - 正则表达式在 regexpal 中工作,但在 Java 中不起作用

客户端通过身份验证时的安全性和 TLS 握手

sockets - 握手后立即发送 WebSocket 消息

sockets - 在 Python 中创建 WebSocket 客户端

java - 建立 SSL 主机连接时无法使用签名证书验证 Cacerts

java - Rest 客户端通过 https 与服务器通信

java - 收到致命警报:SSLHandshakeException中的handshake_failure

java - 从 Windows 中的 Eclipse 中运行 MapReduce 作业时出错