【问题标题】:How can I configure Universal Image Loader to display images from https?如何配置 Universal Image Loader 以显示来自 https 的图像?
【发布时间】:2018-08-28 09:46:02
【问题描述】:

当我与服务器的连接是 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());

【问题讨论】:

  • 你能查出你的ssl证书是否无效吗?
  • @petey 这是一个有效的自签名证书。我对其他服务调用没有任何问题。我也使用 Picasso 并发送 https 请求并可以拍照。如何在 UIL 中配置 ssl?
  • 您应该在问题中添加您使用自签名证书,因为这是您的问题的原因。

标签: android https universal-image-loader


【解决方案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();

【讨论】:

  • 现在我编辑了我的 AuthImageDownloader 并开始工作。谢谢
猜你喜欢
  • 2016-12-13
  • 1970-01-01
  • 2012-12-13
  • 2017-09-08
  • 2014-01-22
  • 2020-03-24
  • 2012-11-19
  • 2013-01-14
  • 2016-07-15
相关资源
最近更新 更多