使用HTTPS的HttpGet:SSLPeerUnverifiedException [英] HttpGet with HTTPS : SSLPeerUnverifiedException
本文介绍了使用HTTPS的HttpGet:SSLPeerUnverifiedException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 HttpClient ,尝试通过HTTPS进行通信时收到以下错误:
Using HttpClient, I receive the following error when attempting to communicate over HTTPS:
线程main中的异常javax.net.ssl.SSLPeerUnverifiedException:peer未经过身份验证。
Exception in thread "main" javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated.
这是我的代码:
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?
推荐答案
使用HttpClient 3.x,你需要这样做:
Using HttpClient 3.x, you need to do this:
Protocol easyHttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
Protocol.registerProtocol("https", easyHttps);
可以找到EasySSLProtocolSocketFactory的实现这里。
An implementation of EasySSLProtocolSocketFactory can be found here.
这篇关于使用HTTPS的HttpGet:SSLPeerUnverifiedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文