解决方案就是
需要 android https HttpsURLConnection 这个类忽略证书
1,找到 Universal-Image-Loader的library依赖包下面com.nostra13.universalimageloader.core.download下面的BaseImageDownloader这个类
里面的createConnection这个方法,添加如下:
1 protected HttpURLConnection createConnection(String url, Object extra) 2 throws IOException { 3 4 try { 5 HttpsURLConnection 6 .setDefaultHostnameVerifier(new NullHostNameVerifier()); 7 SSLContext sc = SSLContext.getInstance("TLS"); 8 sc.init(null, trustAllCerts, new SecureRandom()); 9 HttpsURLConnection 10 .setDefaultSSLSocketFactory(sc.getSocketFactory()); 11 } catch (KeyManagementException e) { 12 e.printStackTrace(); 13 } catch (NoSuchAlgorithmException e) { 14 e.printStackTrace(); 15 } 16 17 String encodedUrl = Uri.encode(url, ALLOWED_URI_CHARS); 18 HttpURLConnection conn = (HttpURLConnection) new URL(encodedUrl) 19 .openConnection(); 20 conn.setConnectTimeout(connectTimeout); 21 conn.setReadTimeout(readTimeout); 22 return conn; 23 }
1 public class NullHostNameVerifier implements HostnameVerifier { 2 3 @Override 4 public boolean verify(String hostname, SSLSession session) { 5 Log.i("RestUtilImpl", "Approving certificate for " + hostname); 6 return true; 7 } 8 9 }
// Create a trust manager that does not validate certificate chains TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String authType) { } } };
参考博客:http://blog.csdn.net/a102111/article/details/44311059
需要直接用改好jar包的下载地址:http://download.csdn.net/detail/yang7162082/8915429
时间: 2024-11-06 20:08:01