Questions
Two days ago, a schoolboy asked a question in the group:
Can you tell me why sending https requests with Ali cloud server fails, is there some other configuration needed?
The same code can access the https interface locally, but not the server, and the server can access the http interface.
HttpsURLConnection is used
I thought it was very interesting, so I asked him to give me the requested URL, and then I tested it on the machine with the curl
command:
Found an error related to SSL, I guess it may be related to the HTTPS certificate. But I couldn’t reach his code and server, so I had to ask him to show me the log in catalina.out
Sure enough, an exception related to SSL was found in the log
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
Why
OK, it’s easy to find exceptions. Take the error message and search Baidu for the solution~
The Internet is talking about the problem of TLS version. The default TLS version of jdk1.7 is 1.0. Just change the TLS version to 1.1 or 1.2
Solutions
Someone raised the same problem in stack overflow
, and Daniel also gave the corresponding solution: javax.net.ssl.sslhandshakeeexception: Remote host closed connection during handshake during web service communication.