【发布时间】:2014-06-06 01:37:24
【问题描述】:
我有一个带有自签名证书的服务器。我已经在我的计算机上使用 keytool 导入它并使用
-Djavax.net.ssl.trustStore=blabla
编译参数。当我尝试运行以下代码时:
SSLSocketFactory factory = HttpsURLConnection.getDefaultSSLSocketFactory();
SSLSocket socket = (SSLSocket) factory.createSocket("MY_URL_DIGITS", 443);
OutputStream os = socket.getOutputStream();
os.write("Test request \n".getBytes());
os.flush();
os.close();
一切正常,我可以在服务器上看到“测试请求”。但是,当我运行时:
URL url = new URL("https://MY_URL_DIGITS");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
OutputStream os = con.getOutputStream();
os.write("Test request \n".getBytes());
os.flush();
os.close();
我收到了
javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names present
那么这两个 sn-ps 的主要区别是什么?
【问题讨论】:
标签: java ssl ssl-certificate