u011183172
u011183172
采纳率100%
2015-05-13 12:01 浏览 1.8k
已采纳

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);
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答 默认 最新

相关推荐