有没有一种方法来指定额外的头,而使用通用图像装载机获取的图像? [英] Is there a way to specify extra headers while fetching images using Universal Image Loader?

查看:86
本文介绍了有没有一种方法来指定额外的头,而使用通用图像装载机获取的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用户通用图像装载机库加载我的图片。我试图调用Web服务API获取图像关闭它,但它需要在客户端附加额外的HTTP标头。即: 访问令牌:124124141241421

I'm trying to user the Universal Image Loader library to load my images. I trying to call a webservice api to fetch images off it, but it requires the client to attach extra http headers. i.e.: Access-Token: 124124141241421

有没有办法来动态地做到这一点在我的项目?

Is there a way to dynamically do this in my project?

推荐答案

您应该实现自己的 ImageDownloader (延伸<一个href="https://github.com/nostra13/Android-Universal-Image-Loader/blob/master/UniversalImageLoader/src/com/nostra13/universalimageloader/core/download/ImageDownloader.java"相对=nofollow> ImageDownloader 类并覆盖的InputStream getStreamFromNetwork(URI imageUri)方法),并将其设置为配置。 看看<一href="https://github.com/nostra13/Android-Universal-Image-Loader/blob/master/UniversalImageLoader/src/com/nostra13/universalimageloader/core/download/URLConnectionImageDownloader.java"相对=nofollow> URLConnectionImageDownloader 这是默认情况下使用,例如。

You should implement your own ImageDownloader (extend ImageDownloader class and override InputStream getStreamFromNetwork(URI imageUri) method) and set it to configuration. Look into URLConnectionImageDownloader which is used by default, for example.

您应该这样做:

HttpURLConnection conn = (HttpURLConnection) imageUri.toURL().openConnection();
conn.setRequestProperty("Access-Token", "124124141241421");

这篇关于有没有一种方法来指定额外的头,而使用通用图像装载机获取的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆