有没有一种方法来指定额外的头,而使用通用图像装载机获取的图像?

问题描述:

我想用户通用图像装载机库加载我的图片。我试图调用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 (延伸 ImageDownloader 类并覆盖的InputStream getStreamFromNetwork(URI imageUri)方法),并将其设置为配置。 看看 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");