21
通过HTTPS使用HttpClient信任所有证书
最近发布了有关HttpClientover Https 的问题(在此处找到)。我取得了一些进展,但遇到了新问题。与我的最后一个问题一样,我似乎找不到适合我的示例。基本上,我希望我的客户端接受任何证书(因为我只指向一台服务器),但是我不断获得javax.net.ssl.SSLException: Not trusted server certificate exception. 这就是我所拥有的: public void connect() throws A_WHOLE_BUNCH_OF_EXCEPTIONS { HttpPost post = new HttpPost(new URI(PROD_URL)); post.setEntity(new StringEntity(BODY)); KeyStore trusted = KeyStore.getInstance("BKS"); trusted.load(null, "".toCharArray()); SSLSocketFactory sslf = new SSLSocketFactory(trusted); sslf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme ("https", sslf, 443)); SingleClientConnManager cm = new SingleClientConnManager(post.getParams(), …