Question

I need to specify a specific Referer for certain images on a remote host to successfully load. (For example, the referrer needs to be "http://www.example.com", otherwise the webserver will return HTTP 403)

AQuery has a section on their wiki about specifying HTTP Headers for ajax calls, but I can't seem to piece together how to do this for a simple async image call.

https://code.google.com/p/android-query/wiki/AsyncAPI#Http_Headers

For example, here is the normal AQuery code used to display an image over the network:

new AQuery(submodelPhoto).image(MyApplication.MEDIA_BASE_URL + getItem(position), true, true, 0, R.drawable.default_image);

How would I specify the HTTP Referer for this call? Is it possible to setup AQuery to do this for every call during my application initialization? (So that it doesn't have to be repeated everytime I try to load an image)

Was it helpful?

Solution

After some digging (and more reading BitmapAjaxCallback) I have come up with this solution:

BitmapAjaxCallback cb = new BitmapAjaxCallback();
cb.header("Referer", "http://www.example.com");
cb.url(MyApplication.MEDIA_BASE_URL + getItem(position)).fallback(R.drawable. default_image).memCache(true).fileCache(true);
new AQuery(submodelPhoto).image(cb);

Seems to work, just wish I could find an approach that would set the referrer for AQuery for every request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top