5

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);
Erik Sapir
  • 23,209
  • 28
  • 81
  • 141

1 Answers1

9

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!

Ian
  • 3,806
  • 2
  • 20
  • 23
  • 4
    Please be aware that Flash can [only send custom headers for `POST` requests](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html#requestHeaders), not `GET` requests. – BlueRaja - Danny Pflughoeft Jan 31 '14 at 20:08
  • 1
    Another important disclaimer - not all headers can be set (especially - Authorization and Cookie headers): http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequestHeader.html – Tom Teman Mar 12 '15 at 13:05