關於weblogic下使用URL.openConnection獲取連線返回javax.net.ssl.SSLKeyException錯誤
阿新 • • 發佈:2019-01-30
本文主要記錄如果解決weblogic使用URL.openConnection出現javax.net.ssl.SSLKeyException:
[Security:
090504
]Certificate
chain received from:xxx.com。。。。。。。的異常,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) { ...... } ..... }