我建立一个简单的应用程序监视器轮询我们的API网址之一,并给我们发电子邮件,如果它不能得到响应一个HTTP 200状态码(这将表明我们的API是因为某些原因)。
我使用的HttpClient 4.1(这是重要的,因为它的API从3.x中有很大的不同)。
我们的API是安全与SSL,但是进入:
http://example.com/our-api
在Web浏览器重定向到
https://example.com/our-api
而不会造成任何错误。
当HttpClient的尝试打这个URL( http://example.com/our-api
)时,出现一个javax.net.ssl.SSLPeerUnverifiedException
有消息指出例外:
同行没有通过认证
我看到这种情况出现了很多其他人如被证明此职位(其中还提供了绕过这个问题的办法-我要尝试,事实上实行今晚的解决方案)。
这是什么其他职位(以及其他类似的人的话)不就是解释为什么这是摆在首位发生! 因此,而不是问“我怎么解决这个问题?” 我想我会问:“ 为什么会这样?”我去与所提出的解决方案之一过驳领先之前,我想知道是什么问题,我正在尝试修复;-)
如果服务器的证书是自签名的,那么这是事先设计好的,你必须将服务器的证书导入到密钥存储。
假设服务器证书是由一个著名的CA签署的,这种情况正在发生,因为一组可用的现代浏览器CA证书的比是随JDK / JRE的有限集合大得多。
在你提到的职位之一给出的解决方案EasySSL刚埋的错误,你就不会知道,如果服务器有一个有效的证书。
您必须导入适当的根CA到密钥存储验证证书。 有你无法解决此获得与股票SSL码一个原因,那就是阻止你编写的行为,如果他们是安全的,但不是程序。
This is thrown when
... the peer was not able to identify itself (for example; no
certificate, the particular cipher suite being used does not support
authentication, or no peer authentication was established during SSL
handshaking) this exception is thrown.
Probably the cause of this exception (where is the stacktrace) will show you why this exception is thrown. Most likely the default keystore shipped with Java does not contain (and trust) the root certificate of the TTP that is being used.
The answer is to retrieve the root certificate (e.g. from your browsers SSL connection), import it into the cacerts
file and trust it using keytool
which is shipped by the Java JDK. Otherwise you will have to assign another trust store programmatically.
keytool -import -v -alias cacerts -keystore cacerts.jks -storepass changeit -file C:\cacerts.cer
我不是一个Java开发人员,但在使用Java应用程序来测试一个RESTful API。 为了使我修正这个错误我必须安装在Web服务器中间证书,从而使错误消失。 我用的lighttpd,原证书安装在IIS服务器上。 希望能帮助到你。 这些都是我在服务器上丢失的证书。
- CA.crt
- UTNAddTrustServer_CA.crt
- AddTrustExternalCARoot.crt