標籤:
解決方案就是
需要 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 HttpsURLConnection10 .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 @Override4 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
Android 開源架構Universal-Image-Loader載入https圖片