android上的httpclient ssl证书

android上的httpclient ssl证书,第1张

概述我在ssl使用httpclient在android上有一些麻烦我试图访问自签名证书的细节我希望我的应用程序信任所有证书(我将使用ssl仅用于数据加密).首先我尝试使用本指南http://hc.apache.org/httpclient-3.x/sslguide.html在桌面上工作正常但在Android上我仍然得到javax.net.ssl.SSLException

我在ssl使用httpclIEnt在android上有一些麻烦我试图访问自签名证书的细节我希望我的应用程序信任所有证书(我将使用ssl仅用于数据加密).首先我尝试使用本指南http://hc.apache.org/httpclient-3.x/sslguide.html在桌面上工作正常但在AndroID上我仍然得到javax.net.ssl.SSLException:不信任的服务器证书.在谷歌搜索后我发现了一些其他的例子如何启用ssl.

http://groups.google.com/group/android-developers/browse_thread/thread/62d856cdcfa9f16e – 当我使用URLConnection但使用httpClIEnt时工作仍然有例外.

http://www.discursive.com/books/cjcook/reference/http-webdav-sect-self-signed.html – 在桌面上使用来自apache的jar工作正在工作,但在androID类中使用包含在SDK类中无法使其工作.

http://mail-archives.apache.org/mod_mbox/hc-httpclient-users/200808.mbox/%3C1218824624.6561.14.camel@ubuntu%3E – 也得到同样的例外

所以任何想法如何使用httpClIEnt信任AndroID上的所有证书

解决方法:

如果你碰巧看看DefaulthttpClIEnt的代码,它看起来像这样:

   @OverrIDe    protected ClIEntConnectionManager createClIEntConnectionManager() {        SchemeRegistry registry = new SchemeRegistry();        registry.register(                new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));        registry.register(                new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));        ClIEntConnectionManager connManager = null;             httpParams params = getParams();        ...    }

请注意https方案到org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory()的映射.

您可以为org.apache.commons.httpclIEnt.protocol.SecureProtocolSocketFactory接口(http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/protocol/SecureProtocolSocketFactory.html)创建自定义实现,其中,您可以使用接受所有证书的自定义TrustManager创建java.net.SSLSocket.

您可能希望在http://java.sun.com/j2se/1.4.2/docs/guide/security/jsse/JSSERefGuide.html查看JsSE以获取更多详细信息

总结

以上是内存溢出为你收集整理的android上的httpclient ssl证书全部内容,希望文章能够帮你解决android上的httpclient ssl证书所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1100620.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存