带 HTTPS 的 HttpGet:SSLPeerUnverifiedException [英] HttpGet with HTTPS : SSLPeerUnverifiedException
本文介绍了带 HTTPS 的 HttpGet:SSLPeerUnverifiedException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 HttpClient,我在尝试通过 HTTPS 通信时收到以下错误:><块引用>
线程main"中的异常 javax.net.ssl.SSLPeerUnverifiedException: peer not authentication.
这是我的代码:
URI loginUri = new URI("https://myUrl.asp");HttpClient httpclient = new DefaultHttpClient();HttpGet httpget = new HttpGet( loginUri );HttpResponse 响应 = httpclient.execute( httpget);
如何抑制或消除此错误?
解决方案
使用HttpClient 3.x,你需要这样做:
Protocol easyHttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);Protocol.registerProtocol("https", easyHttps);
可以找到 EasySSLProtocolSocketFactory 的实现 这里.
Using HttpClient, I receive the following error when attempting to communicate over HTTPS:
Exception in thread "main" javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated.
Here is my code:
URI loginUri = new URI("https://myUrl.asp");
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet( loginUri );
HttpResponse response = httpclient.execute( httpget );
How do I suppress or remove this error?
解决方案
Using HttpClient 3.x, you need to do this:
Protocol easyHttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
Protocol.registerProtocol("https", easyHttps);
An implementation of EasySSLProtocolSocketFactory can be found here.
这篇关于带 HTTPS 的 HttpGet:SSLPeerUnverifiedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文