javax.net.ssl.SSLHandshakeException HttpsURLConnection

时间:2016-04-07 20:16:55

标签: java ssl

我得到一个“线程中的异常”主要“javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure”,代码如下。有人知道如何解决它吗?

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;

public class Test {
static {
    System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2,SSLv3,SSLv2Hello");
    HostnameVerifier hv = new HostnameVerifier() {
        public boolean verify(String urlHostName, SSLSession session) {
            return true;
        }
    };
    HttpsURLConnection.setDefaultHostnameVerifier(hv);
}

public static void main(String[] args) throws MalformedURLException, IOException {
    HttpURLConnection con = (HttpsURLConnection) new URL("https://www.sureworks.de").openConnection();
    con.connect();
}
}

1 个答案:

答案 0 :(得分:0)