Android的SSL错误:证书不被信任......有时候 [英] Android SSL error: certificate not trusted...sometimes

查看:179
本文介绍了Android的SSL错误:证书不被信任......有时候的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用我的工作,我必须做出一个HTTPS连接到Web服务器。我是越来越不被信任的证书错误和咨询计算器后,我发现这个博客帖子: http://blog.antoine.li/index。 PHP / 2010/10 / Android的信任-SSL-证书/

In the app I'm working on, I have to make an HTTPS connection to a web server. I was getting certificate not trusted errors and after consulting stackoverflow, I found this blog posting: http://blog.antoine.li/index.php/2010/10/android-trusting-ssl-certificates/

这似乎是CA在该服务器没有包含在Android的默认存储。概括地说,我下载的所有证书,创建密钥库与BKS供应商,进口按键,输入密钥存储到我的项目,子类的DefaultHttpClient类,迫使它用我的密钥库。

It seems like the CA for this server is not included in Android's default store. In a nutshell, I downloaded all the certificates, created a keystore with the BKS provider, imported the keys, imported the keystore into my project, subclassed the DefaultHttpClient class to force it to use my keystore.

下面在博客中的步骤后,它的工作完全在模拟器上。然而,当我测试的设备上,它没有间断。我想我已经分离出了一种模式。好像过了一段时间已经过去了,我尽量让HTTPS连接,它将会失败。然后,如果我再次尝试相同的连接,它就会成功。如果我等待一段时间,然后再试一次,失败了一次,成功上反复尝试。我大概可以修复它​​通过只是让失败多次尝试,但我想知道是怎么回事。该行为表明某种缓存,但我不知道如何去寻找它或改变其行为。有没有人有关于正在发生的事情有任何建议或知道我做错了什么?任何帮助将是AP preciated。

After following the steps in the blog, it worked perfectly on the emulator. However, when I test it on a device, it fails intermittently. I think I've isolated a pattern. It seems like after some time has passed and I try to make an HTTPS connection, it will fail. Then, if I attempt the same connection again, it will succeed. If I wait a while and then try again, it fails the first time, succeeds on repeated attempts. I can probably fix it by just making multiple attempts on failure, but I would like to know what is going on. The behavior suggests some kind of cache but I don't know how to go about finding it or modifying its behavior. Does anyone have any suggestions about what is going on or know what I'm doing wrong? Any help would be appreciated.

推荐答案

我通过设置解决了类似的问题。

I solved a similar problem by setting

System.setProperty("http.keepAlive", "false");

在我做我的HTTP调用。似乎有与Android的问题保持关闭的连接在连接池,并试图重新使用它们。

before I did my HTTP calls. There seems to be a problem with Android keep closed connections in its connection pool and trying to reuse them.

这篇关于Android的SSL错误:证书不被信任......有时候的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆