javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

問題

前兩天一個學弟在羣裏面問一個問題:java

請問一下用阿里雲服務器發送https請求爲何會失敗,是須要有些其餘什麼配置嗎?
一樣的代碼本地能夠訪問https接口,服務器不行,並且服務器能夠訪問http接口。
用的HttpsURLConnection

以爲挺有意思,就叫他把請求的URL給一下,而後我在機器上用curl命令測試了一把: 這裏寫圖片描述web

發現報了與ssl有關的錯誤,我推測可能與https證書有關。 可是他的代碼和服務器我都接觸不到,只好叫他把catalina.out裏面的日誌給我看下。安全

果真在日誌裏面發現了一個與ssl相關的Exception:服務器

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
	at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1002)
	... more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
	at sun.security.ssl.InputRecord.read(InputRecord.java:505)
	... more

緣由

ok,找到Exception就好辦了,拿着錯誤信息上百度搜一下解決方法就有了~curl

網上說的是TLS版本的問題,jdk1.7默認的TLS版本是1.0,將TLS版本改爲1.1或者1.2就行了測試

解決方法

有人在Stack Overflow提了相同的問題,而且大牛們也給了相應的解決方案: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake during web service communicaiton阿里雲

延伸閱讀:

相關文章
相關標籤/搜索