Java 如何检查HTTPS连接的SSL配置是否有效?
我正在尝试编写一个实用程序类(因为我还没有找到),它允许我检查HTTPS连接是否正常。当我卷曲站点时,我得到了错误Java 如何检查HTTPS连接的SSL配置是否有效?,java,ssl,https,Java,Ssl,Https,我正在尝试编写一个实用程序类(因为我还没有找到),它允许我检查HTTPS连接是否正常。当我卷曲站点时,我得到了错误 curl: (60) SSL certificate problem: Invalid certificate chain 当我在Chrome上访问该网站时,我会 The identity of this website has not been verified. Server's certificate does not match the URL. The server c
curl: (60) SSL certificate problem: Invalid certificate chain
当我在Chrome上访问该网站时,我会
The identity of this website has not been verified. Server's certificate does not match the URL. The server could not prove that is is *.domain.com; its security certificate is from *.another.com.
这正是我想在Java中测试的内容,但我一直未能做到这一点。如何测试SSL连接是否正常?一种简单的方法是访问给定的URL。如果连接正常,则必须返回HTTP 200 OK响应代码,否则Java请求库(例如Java的
HttpsUrlConnection
、Apache的HttpCLient
、Ning的HttpCLient
应返回异常
这是非常基本的,但取决于您的需要。您可能会使用
javax.net.ssl.SSLHandshakeException
Caveat:curl和Java在一般情况下(部分)使用不同的TLS配置(特别是独立的信任库)。因此,您可能仍然会从Java和curl中得到不同的结果。