1

I have the following code:

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

I have this code for downloading files. And when I am executin it i get this IOException error that I can not find on any page:

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

I test it on Android 4.3 and it works normaly but not on 2.3. Any idea what can go wrong. It also work fine in browser and on iOS. I aslo check certificate on http://www.sslshopper.com/ and everythink works fine

ButterBeast
  • 521
  • 10
  • 25
  • This is a known (old Android) error: http://stackoverflow.com/questions/21183043/sslhandshakeexception-trust-anchor-for-certification-path-not-found-android-http http://stackoverflow.com/questions/21306336/android-2-3-x-javax-net-ssl-sslhandshakeexception-java-security-cert-certpathva – shkschneider Apr 30 '14 at 12:57
  • I found this, but I do not want to add any .crt file. Is it any other walk around? – ButterBeast Apr 30 '14 at 13:18

1 Answers1

0

I found the solution that works perfect. Instead of using URLConection I used HttpClient:

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url.toString());
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
ButterBeast
  • 521
  • 10
  • 25