您的位置:首页 > 编程语言 > Java开发

关于weblogic下使用URL.openConnection获取连接返回javax.net.ssl.SSLKeyException错误

2015-10-10 15:14 501 查看
本文主要记录如果解决weblogic使用URL.openConnection出现
javax.net.ssl.SSLKeyException:
[Security:
090504
]。。。。。。。的异常,tomcat下一切正常。


在解决问题之前查看了http://blog.csdn.net/arvinrong/article/details/7715334和http://winters1224.blog.51cto.com/3021203/1313111这两篇文章的建议(感谢两位作者),原因这两位分析的很清晰了,最终采用一种简单的方式(无须修改weblogic代理配置),如下:

URL url = new URL(null,urlStr,new sun.net.www.protocol.https.Handler());//重点在这里,需要使用带有URLStreamHandler参数的URL构造方法  
HttpsURLConnection httpConnection = (HttpsURLConnection) url.openConnection();//由于我调用的是官方给微信API接口,所以采用HTTPS连接  
int responseCode = httpConnection.getResponseCode();  
if (responseCode == HttpURLConnection.HTTP_OK) {  
    InputStream urlStream = httpConnection.getInputStream();  
    BufferedReader bufferedReader = new BufferedReader(  
            new InputStreamReader(urlStream));  
    String lineStr = "";  
    while ((lineStr = bufferedReader.readLine()) != null) {  
        ......  
    }  
    .....  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  weblogic