使用 HttpClient POST 到表单但出现 SSLPeerUnverifiedException 但浏览器工作正常
使用 HttpClient 4.1.0,我们尝试连接到通常使用表单连接的远程服务器。顺便说一句,这将用于生产用途,但我不会称我们发送的信息为敏感信息。我不确定他们是否会坚持使用 https 连接。
当我们尝试调用 httpClient.execute(httpPost) 时,它会抛出 SSLPeerUnverifiedException。
我们正在使用 ThreadSafeClientConnManager 创建 DefaultHttpClient,并已验证 https 注册表是否与 SSLSocketFactory 关联。
我们连接到这样的网址: https://some.thingchangedtoprotectthem.com/servlet/servlet .Something
为什么浏览器会像魅力一样工作,但使用服务器端进程会因该异常而崩溃?是因为浏览器自带verisign证书而HttpClient没有?
System.out and Stack trace below:
schemeSocketFactory = org.apache.http.conn.ssl.SSLSocketFactory
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
at com.sun.net.ssl.internal.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:345)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:390)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:562)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
Using HttpClient 4.1.0, we're trying to connect to a remote server that normally would be connected to using a form. By the way, this will be for production use but I would not call the information we're sending sensitive. I'm not sure if they will insist on an https connection anyway.
When we try to call httpClient.execute(httpPost), it throws a SSLPeerUnverifiedException
We're creating a DefaultHttpClient using a ThreadSafeClientConnManager and have verified that the https registry is associated with a SSLSocketFactory.
We're connecting to a url like this: https://some.thingchangedtoprotectthem.com/servlet/servlet.Something
Why would the browser work like a charm, but using a server side process blows up with that exception? Is it because the browser comes with verisign certificates and HttpClient does not?
System.out and Stack trace below:
schemeSocketFactory = org.apache.http.conn.ssl.SSLSocketFactory
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
at com.sun.net.ssl.internal.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:345)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:390)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:562)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确实是的。您应该看看这篇博客文章< /a> 作者在其中描述了如何在密钥库中下载和安装证书。它是为 Android 开发人员撰写的文章,但它绝对适用于您的情况。
最坏的情况,这个问题将告诉您如何信任所有证书,虽然这不是一个好主意。 ;)
Yes indeed. You should to have a look at this blog post where the author describes how to download and install a certificate in your keystore. It's written as an article for Android developers, but it most definitely applies to your case.
Worst case, this question will tell you how to trust all certificates, though that's not a very good idea. ;)
“是不是因为浏览器自带了verisign证书而HttpClient没有?”
几乎可以肯定。
请参阅此消息以获取有关如何修复它的想法。
"Is it because the browser comes with verisign certificates and HttpClient does not?"
Almost certainly.
See this message for ideas on how to fix it.