Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何检查HTTPS连接的SSL配置是否有效?_Java_Ssl_Https - Fatal编程技术网

Java 如何检查HTTPS连接的SSL配置是否有效?

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

我正在尝试编写一个实用程序类(因为我还没有找到),它允许我检查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 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中得到不同的结果。