当我与服务器的连接是https时,我遇到Universal Image Loader的问题。我可以使用http显示图像,但不能使用https连接显示图像。如何在UIL中设置sslSocketFactory?我的UIL代码如下所示;
Map<String,String> authHeaders = new HashMap<>();
authHeaders.put("token", LocalStorage.getUserToken(ctx));
DisplayImageOptions defaults = new DisplayImageOptions.Builder()
.displayer(new FadeInBitmapDisplayer(300, true, true, false))
.showImageOnFail(R.drawable.ic_image_fail)
.showImageForEmptyUri(R.drawable.ic_image_fail)
.cacheOnDisk(true)
.cacheInMemory(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.extraForDownloader(authHeaders)
.build();
ImageLoaderConfiguration.Builder configsBuilder = new ImageLoaderConfiguration.Builder(ctx)
.imageDownloader(new AuthImageDownloader(ctx))
.defaultDisplayImageOptions(defaults);
ImageLoader.getInstance().init(configsBuilder.build());
答案 0 :(得分:1)
开球样本:
public class SslRuinedDownloader extends BaseImageDownloader {
public SslRuinedDownloader(Context context) {
super(context);
}
@Override
protected HttpURLConnection createConnection(String url, Object extra) throws IOException {
HttpsURLConnection conn = super.createConnection(url, extra);
//here you go
conn.setSSLSocketFactory(...);
return conn;
}
}
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.imageDownloader(new SslRuinedDownloader(getApplicationContext()))
.build();