u011183172
2015-05-13 12:01
采纳率: 100%
浏览 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条回答 默认 最新

  • sunfeilong1993 2015-05-13 13:15
    已采纳

    http://demo.netfoucs.com/will_awoke/article/details/38587467
    看楼主看一下把,不知道能解决你的问题不能

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • 东东东雷 2015-05-14 02:37

    这个应该是 访问的是 https 这个需要安装SSL证书,这个自己百度做吧。

    评论
    解决 无用
    打赏 举报
  • 微wx笑 2015-05-16 04:28

    需要为httpConn 设置证书,
    参考:http://wenku.baidu.com/link?url=kwEOwMY5CCncSPEuSRdTlwKZb0uNgiyaqex5iqL93YIh2yRQ8pGapptv57R69rY2ZX3M2_mN4TGSoXg-qQO7-9uK938giaDDuMwdeqsOoci
    使用HttpsURLConnection + X509TrustManager  发送数据

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题