zyhworker / httpclientandroidlib

Automatically exported from code.google.com/p/httpclientandroidlib
Other
0 stars 0 forks source link

加载正确的证书访问https服务时,android4.0以下版本报错 #14

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

加载正确的证书,去访问https服务。4.0以下版本的android会提��
�找不到证书位置的错误,
代码如下:
 KeyStore trustStore  = KeyStore.getInstance(KeyStore.getDefaultType());
                ins = context.getResources().openRawResource(R.raw.huipumobile); // 下载的证书放到项目中的assets目录中
                 trustStore.load(ins, "123456".toCharArray());
                 SSLContext sslcontext = SSLContexts.custom()
                    .loadTrustMaterial(trustStore)
                    .build();

            SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext,
                    SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
            httpClient = HttpClients.custom()
                    .setSSLSocketFactory(sslsf)
                    .build();

Original issue reported on code.google.com by lq123456...@gmail.com on 23 Jan 2014 at 12:04

GoogleCodeExporter commented 9 years ago
What exactly is the problem/error message?
In english please :)

Original comment by dirkb...@gmail.com on 23 Jan 2014 at 8:17

GoogleCodeExporter commented 9 years ago
Google translator gives me this:
"Load the correct credentials, to access https services. The following versions 
of android 4.0 will prompt an error can not find the location of the 
certificate, 
Code is as follows:"

Original comment by zam...@gmail.com on 9 Apr 2014 at 4:16