有没有办法在使用Universal Image Loader获取图像时指定额外的标题?

我正在尝试使用Universal Image Loader库来加载我的图像。 我试图调用webservice api来获取它的图像,但它需要客户端附加额外的http头。 即:访问令牌:124124141241421

有没有办法在我的项目中动态执行此操作?

您应该实现自己的ImageDownloader (扩展ImageDownloader类并覆盖InputStream getStreamFromNetwork(URI imageUri)方法)并将其设置为配置。 查看默认使用的URLConnectionImageDownloader ,例如。

你应该这样做:

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