httpclient ssl certificate on android(android上的httpclient ssl证书)
问题描述
我在使用 ssl 在 android 上使用 httpclient 时遇到了一些问题我正在尝试详细访问自签名证书我希望我的应用程序信任所有证书(我将仅使用 ssl 进行数据加密).首先我尝试使用本指南 http://hc.apache.org/httpclient-桌面上的 3.x/sslguide.html 工作正常,但在 android 上我仍然得到 javax.net.ssl.SSLException: Not trust server certificate.在谷歌搜索后,我发现了一些其他如何启用 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 类中包含的无法使其工作.p>
http://mail-archives.apache.org/mod_mbox/hc-httpclient-users/200808.mbox/%3C1218824624.6561.14.camel@ubuntu%3E - 也得到同样的例外
所以任何想法我如何使用 HttpClient 信任 android 上的所有证书
如果你碰巧看到 DefaultHttpClient 的代码是这样的:
@Override受保护的 ClientConnectionManager createClientConnectionManager() {SchemeRegistry 注册表 = new SchemeRegistry();注册表.注册(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));注册表.注册(新方案(https",SSLSocketFactory.getSocketFactory(),443));ClientConnectionManager connManager = null;HttpParams 参数 = 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
I have some troubles with ssl using httpclient on android i am trying to access self signed certificate in details i want my app to trust all certificates ( i will use ssl only for data encryption). First i tried using this guide http://hc.apache.org/httpclient-3.x/sslguide.html on Desktop is working fine but on android i still got javax.net.ssl.SSLException: Not trusted server certificate. After searching in google i found some other examples how to enable ssl.
http://groups.google.com/group/android-developers/browse_thread/thread/62d856cdcfa9f16e - Working when i use URLConnection but with HttpClient still got the exception.
http://www.discursive.com/books/cjcook/reference/http-webdav-sect-self-signed.html - on Desktop using jars from apache is working but in android using included in SDK classes can't make it work.
http://mail-archives.apache.org/mod_mbox/hc-httpclient-users/200808.mbox/%3C1218824624.6561.14.camel@ubuntu%3E - also get the same exception
So any ideas how can i trust all certificates on android using HttpClient
If you happen to look at the code of DefaultHttpClient, it looks something like this:
@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();
...
}
Notice the mapping of https scheme to org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory().
You can create a custom implementation for org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory
interface (http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/protocol/SecureProtocolSocketFactory.html) wherein, you can create java.net.SSLSocket
with a custom TrustManager
that accepts all certificate.
You may want to look into JSSE for more details at http://java.sun.com/j2se/1.4.2/docs/guide/security/jsse/JSSERefGuide.html
这篇关于android上的httpclient ssl证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:android上的httpclient ssl证书


- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01