【发布时间】:2016-07-28 22:26:12
【问题描述】:
我收到以下代码的“线程“主”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();
}
}
【问题讨论】:
-
如果你用
-Djavax.net.debug=ssl运行JVM会有什么输出? -
您使用什么版本的 Java 运行测试?使用 SSLLabs 测试该站点表明需要 SNI 支持才能连接到该站点。这需要 Java 1.7 或更高版本。