问题描述
- J2EE做的网站,要访问其他网站
-
就出现以下异常:
javax.net.ssl.SSLProtocolException: handshake alert: unrecognized_name
at sun.security.ssl.ClientHandshaker.handshakeAlert(ClientHandshaker.java:1292)
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1952)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1077)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
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:1300)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at com.mymap.model.CaptureJavascript.getPosition(CaptureJavascript.java:60)尝试照网上说的添加: **System.setProperty("jsse.enableSNIExtension", "false");** 但是无效。 以下是我的代码。该方法在Capture类中,servlet类中调用Capture类的方法,方法代码如下: private double[] getPosition(double lat, double lon) throws Exception { System.setProperty("jsse.enableSNIExtension", "false"); String strURL = "https://eosweb.larc.nasa.gov/cgi-bin/sse/grid.cgi?&num=230000&lat=" + lat + "&submit=Submit&veg=17&p=swv_dwn&step=2&lon=" + lon; //"https://eosweb.larc.nasa.gov/cgi-bin/sse/grid.cgi?&num=199997&lat=" + lat + "&submit=Submit&veg=17&p=swv_dwn&step=2&lon=" + lon; URL url = new URL(strURL); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); InputStreamReader input = new InputStreamReader(httpConn.getInputStream(), "utf-8"); BufferedReader bufReader = new BufferedReader(input); StringBuilder contentBuf = new StringBuilder(); String line = ""; while((line = bufReader.readLine()) != null) { contentBuf.append(line); } String buf = contentBuf.toString(); int beginIx = buf.indexOf("year Average"); int endIx = buf.indexOf("Minimum And Maximum Difference"); String resultstr = buf.substring(beginIx, endIx); return getDoubles(resultstr); }
解决方案
http://demo.netfoucs.com/will_awoke/article/details/38587467
看楼主看一下把,不知道能解决你的问题不能
解决方案二:
这个应该是 访问的是 https 这个需要安装SSL证书,这个自己百度做吧。
解决方案三:
需要为httpConn 设置证书,
参考:http://wenku.baidu.com/link?url=kwEOwMY5CCncSPEuSRdTlwKZb0uNgiyaqex5iqL93YIh2yRQ8pGapptv57R69rY2ZX3M2_mN4TGSoXg-qQO7-9uK938giaDDuMwdeqsOoci
使用HttpsURLConnection?+?X509TrustManager??发送数据
时间: 2025-01-31 06:04:39