首页 > 代码库 > SSL handshake alert: unrecognized_name error since upgrade to Java 1.7

SSL handshake alert: unrecognized_name error since upgrade to Java 1.7

今天将jdk从1.6升级到1.7,但是HttpUrlConnection连接https出现问题了。

javax.net.ssl.SSLProtocolException: handshake alert:  unrecognized_name    at sun.security.ssl.ClientHandshaker.handshakeAlert(ClientHandshaker.java:1288)    at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1904)    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1027)    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1262)    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1289)    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1273)    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:523)    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1296)    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)    at java.net.URL.openStream(URL.java:1035)
 

问谷大哥,原来是jdk版本的问题,解决方法在代码前加上

System.setProperty("jsse.enableSNIExtension", "false");

在overflowstack上有更详细的解释,猛击下面的链接地址查看

http://stackoverflow.com/questions/7615645/ssl-handshake-alert-unrecognized-name-error-since-upgrade-to-java-1-7-0

SSL handshake alert: unrecognized_name error since upgrade to Java 1.7