Reputation: 2446
I'm building an Adobe Air app that needs to load external images from different webservers. I have my basic loader function set up, but I encountered one server that wouldn't let me load it's images. it gave me the following error:
Error #2036: Load Never Completed. URL: http://www.url.com/folder/image.jpg
After that I got in contact with the server's manager and he told me he had been working on some basisc hotlink protection for his images. He also told me that I could subvert this by supplying 'http://www.url.com' as the referrer when building the request headers.
First of all I found no trace of hotlink protection with online testapplications for hotlink protection. Secondly I have no idea how to set up what he told me with a simple Loader class function.
my current code:
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadImages);
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, imgLoadErrorHandler);
_loader.load(new URLRequest(encodeURI(pictureUrl)));
Upvotes: 0
Views: 704
Reputation: 763
You should add an HTTP header to your URLRequest
var refererHeader:URLRequestHeader = new URLRequestHeader('Referer', 'http://www.url.com');
var request:URLRequest = new URLRequest(encodeURI(pictureUrl));
request.requestHeaders.push(refererHeader);
loader.load(request);
Refer ;) to http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequestHeader.html about more info and samples of adding HTTP headers to an URLRequest and http://www.w3.org/Protocols/HTTP/HTRQ_Headers.html#z14 and http://en.wikipedia.org/wiki/HTTP_referrer about the HTTP Refere header
Update: Unfortunately this doesn't work for the Referer header according to Exort (and Adobe documentation after a closer look)
Upvotes: 2
Reputation: 1075
You can't change the referer header in Flex, even by using Treur's technique. There one or two headers like this in AIR that are protected and will always be overwrittent (cookie is one of them too if I'm not mistaken). I had a bunch of problems with this similar to what you have but with SWF files.
A standard browser will send an empty referer by default. An AIR app will send itself as the default renderer (something like app:/Main.swf). You can easily see that by using a web debugging proxy, such as Charles http://www.charlesproxy.com/ This causes some requests to be automatically refused.
Here's a thread about it on Adobe Forums : http://forums.adobe.com/message/3868365
Here's a bug I opened at Adobe Bugbase. It's currently opened with a 3-High priority and has been aknowledged by Adobe. I don't know if it will be fixed eventually. https://bugbase.adobe.com/index.cfm?event=bug&id=2945647
You can also vote for a fix at Adobe Labs Ideas : http://ideas.adobe.com/ct/ct_a_view_idea.bix?c=9D564F43-979A-4E35-AA21-85A61B6AB8DE&idea_id=CA6C107B-CE93-4DAF-82EA-503C4DB2B1F8
Upvotes: 3