【问题标题】:Android 2.3 Error: Not a CA CertificateAndroid 2.3 错误:不是 CA 证书
【发布时间】:2014-06-16 19:00:33
【问题描述】:

我有以下代码:

HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
    conn.setConnectTimeout(60000); //set timeout to 60 seconds      
    conn.connect();

    InputStream input = new BufferedInputStream(url.openStream());
    OutputStream output = new FileOutputStream(filePath);   
    byte data[] = new byte[1024];
    long total = 0;

    while ((count = input.read(data)) != -1) {
        output.write(data, 0, count);
    }

    output.close();
    input.close();

我有这个下载文件的代码。当我执行它时,我得到这个在任何页面上都找不到的 IOException 错误:

javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Not a CA certificate

我在 Android 4.3 上对其进行了测试,它可以正常工作,但不能在 2.3 上运行。知道会出什么问题。它在浏览器和 iOS 上也可以正常工作。我还检查了http://www.sslshopper.com/ 上的证书,everythink 工作正常

【问题讨论】:

标签: android ssl-certificate


【解决方案1】:

我找到了完美的解决方案。我没有使用 URLConection,而是使用了 HttpClient:

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url.toString());
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();

【讨论】:

    猜你喜欢
    • 2015-01-29
    • 2023-03-14
    • 2014-10-21
    • 2014-12-15
    • 1970-01-01
    • 2017-12-11
    • 2015-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多