2014-04-30 90 views
1

我有以下代碼:Android 2.3的錯誤:不是CA證書,

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(); 

我對下載文件的代碼。而當我executin它,我得到這個錯誤IOException異常,我不能在任何網頁上找到:

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

我測試它在Android 4.3和它的作品normaly但不是2.3。任何想法可能會出錯。它在瀏覽器和iOS上也可以正常工作。我也檢查http://www.sslshopper.com/和everythink正常工作證書

+0

這是一個已知的(舊的Android)錯誤:http://stackoverflow.com/questions/21183043/sslhandshakeexception-trust-anchor-for-certification-path-not-發現-Android-http http://stackoverflow.com/questions/21306336/android-2-3-x-javax-net-ssl-sslhandshakeexception-java-security-cert-certpathva – shkschneider

+0

我發現這個,但我不想要添加任何.crt文件。還有其他的走動嗎? – ButterBeast

回答

0

我發現了完美的解決方案。而不是使用URLConection我用的HttpClient:

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