我有以下代码:
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/上的证书,并且每个方面都可以正常工作
答案 0 :(得分:0)
我找到了完美的解决方案。我没有使用URLConection,而是使用了HttpClient:
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url.toString());
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();