imageloader 的 java.security.cert.CertPathValidatorException
最近使用imageloader 發(fā)現(xiàn)ssl問題 (java.security.cert.CertPathValidatorException)
網(wǎng)上找了個方法,親測通過,如下:
universalimageloader/core/download/BaseImageDownloader.java文件中
protected HttpURLConnection createConnection(String url, Object extra)
throws IOException {
FakeX509TrustManager.allowAllSSL();// 允許所有ssl證書
String encodedUrl = Uri.encode(url, ALLOWED_URI_CHARS);
HttpURLConnection conn = (HttpURLConnection) new URL(encodedUrl)
.openConnection();
conn.setConnectTimeout(connectTimeout);
conn.setReadTimeout(readTimeout);
return conn;
}
public static class FakeX509TrustManager implements X509TrustManager {
private static TrustManager[] trustManagers;
private static final X509Certificate[] _AcceptedIssuers = new X509Certificate[0];
public void checkClientTrusted(X509Certificate[] x509Certificates,
String s) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] x509Certificates,
String s) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return _AcceptedIssuers;
}
public static void allowAllSSL() {
HttpsURLConnection
.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
SSLContext context = null;
if (trustManagers == null) {
trustManagers = new TrustManager[] { new FakeX509TrustManager() };
}
try {
context = SSLContext.getInstance("TLS");
context.init(null, trustManagers, new SecureRandom());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(context
.getSocketFactory());
}
}
總結(jié)
以上是生活随笔為你收集整理的imageloader 的 java.security.cert.CertPathValidatorException的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 中的invalidate
- 下一篇: 透视映射和射影映射的关系 Perspec