Android的凌空ImageLoader的 - 如何使用基本HTTP授权? [英] Android Volley ImageLoader - How to use Basic HTTP Authorization?

查看:110
本文介绍了Android的凌空ImageLoader的 - 如何使用基本HTTP授权?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我需要基本的HTTP授权REST API使用排的 NetworkImageView 加载图像。所以,我需要的头添加到HTTP请求。​​

I want to use Volley's NetworkImageView to load images from my REST API that needs Basic HTTP Authorization. So i need to add headers to HTTP Request.

我做了以下方法:

替换 Request.getHeaders() - 在的这个问题。 这将是很好,但问题是, ImageLoader的新ImageRequest()硬codeD这样我就可以'T通过我的要求执行到 ImageLoader的,它不容易被继承和调整(我需要的方法重新实现使用私有属性)。

Override Request.getHeaders() - as described in this question. This would be fine, but the problem is that ImageLoader has new ImageRequest() hardcoded so I can't pass my Request implementation into ImageLoader and it cannot be easily inherited and tweaked (the method i'd need to reimplement uses private properties).

解决的办法是修改排球库本身(我想避免)。

The solution is to modify Volley library itself (what i'd like to avoid).

使用自定义HttpClientStack - 所描述的这里。 使用这种方法,我会截取HTTP交际,并添加必需的头。但我认为这是不正确的方式去做 - 我会失去自动选择的HttpClient通过排球(姜饼与HC与IC)

Use Custom HttpClientStack - as described here. Using this approach i'd be able to intercept HTTP comunication and add necessary headers. But I think this is not the right way to do - I'd loose automatic selection of HttpClient by Volley (Gingerbread vs. HC and IC).

有一些simplier办法才达到这一点,我很想念?

Is there some simplier way to achive this that I'm missing?

推荐答案

我已经重写 getHeaders()为好。到目前为止,我还没有找到一种方法来做到这一点更容易。

I have overriden getHeaders() as well. So far I haven't found a way to do that more easily.

请参阅本例中的https://github.com/njzk2/VolleyTwitter/blob/master/src/com/njzk2/twitterbrowser/TokenRequest.java一个被覆盖的请求,包括授权头。

See this example https://github.com/njzk2/VolleyTwitter/blob/master/src/com/njzk2/twitterbrowser/TokenRequest.java of an overriden Request to include the Authorization header.

这是凌空code,我没有看到任何方式添加自定义头文件,如果没有通过重写请求的对象。

From Volley code, I don't see any way of adding custom headers if not by overriding the Request object.

另外,我看不出它可以很容易地添加给排球的结构,对于图像,ImageRequests由ImageLoader的创建。

Moreover, I don't see how it can be easily added given the structure of Volley, as for the Images, ImageRequests are created by the ImageLoader.

如果我要修改凌空允许这样做,我将有可能使用自定义类在ImageLoader的延伸ImageRequest。在ImageLoader的匿名ImageRequest类使得它有点复杂,但。

If I were to modify Volley to allow this, I would make it possible to use a custom class extends ImageRequest in the ImageLoader. The anonymous ImageRequest class in ImageLoader makes it a bit complicated, though.

这篇关于Android的凌空ImageLoader的 - 如何使用基本HTTP授权?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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