Java HttpsURLConnection SSLHandshakeException
我正在尝试使用Java HttpsURLConnection SSLHandshakeException,java,https,http-put,sslhandshakeexception,Java,Https,Http Put,Sslhandshakeexception,我正在尝试使用HttpsURLConnection与网站建立HTTPS连接,然后执行PUT请求。当我尝试从HttpsURLConnection.getOutputStream()创建OutputStreamWriter时,会引发以下异常: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.c
HttpsURLConnection
与网站建立HTTPS连接,然后执行PUT请求。当我尝试从HttpsURLConnection.getOutputStream()
创建OutputStreamWriter
时,会引发以下异常:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target
该页面刚刚获得了它的证书(由StartCom颁发)-我是否需要手动执行一些操作以使Java识别证书是否存在?我可以毫不费力地连接到同一网站的其他页面,但它们有不同的证书。您可以将StartCom yia的根证书导入Java密钥存储(JKS)中,然后将密钥存储设置为“可信存储” 请参见“导出和导入证书”一节: 文章中提到的命令: 将证书导入trustedcerts.jks:
keytool -import -keystore trustedcerts.jks -alias qusay -file server.crt
使用自定义tuststore启动Java:
java -Djavax.net.ssl.trustStore=trustedcerts.jks com.example.MyClass
或者,您可以在运行时设置信任库:
System.setProperty("javax.net.ssl.trustStore","./trustedcerts.jks");
另请参见以下问题:
它链接到一个脚本,用于将StartCom证书导入您的JDK可信存储。谢谢-对于其他有相同问题的人,我在本地保存了证书,使用
keytool-import…
命令并添加了System.setProperty(“javax.net.ssl.trustStore”,“path_to_keystore”)代码>到我的代码。