I want to add Authorization header to my requests.
I added the following line in crossdomain.xml of the server:
<allow-http-request-headers-from domain="*" headers="Authorization"/>
And still, the header is not sent (checked with Wireshark).
Am i missing something?
EDIT:
the code of the urlRequest:
var request:URLRequest = new URLRequest();
request.method = URLRequestMethod.POST;
request.url = this.uploadURL;
request.data = post;
var requestHeader:URLRequestHeader = new URLRequestHeader("Authorization", "Basic ZXNhcGlyK2xhQGdtYWlsLmNvbTpFcmlrU2FwaXIyOQ==");
request.requestHeaders.push(requestHeader);
Here's an implementation that I recently made that worked great for me :
var url:String = _baseURL + "/utils.php";
var headers:Array = [
new URLRequestHeader("_sessionKey", _sessionKey),
new URLRequestHeader("_userId", _sessionUserId)
];
var request:URLRequest = new URLRequest();
request.requestHeaders = headers;
request.method = URLRequestMethod.POST;
request.url = url;
///////////////////
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT; //don't know if this is really needed
loader.addEventListener(Event.COMPLETE, handleSuccess);
loader.addEventListener(IOErrorEvent.IO_ERROR, handleError);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleError);
loader.load(request);
The only big difference that I can see is that I am creating a new array with the headers in it, then assigning that to the requestHeaders
property of request
, instead of creating a new URLRequestHeader and trying to push it directly into request.requestHeaders
. Everything else looks pretty good to me.
Hope this helps! And good luck!