XMLHttpRequest / Authorization Header

It seems like I can't add an Authorization Header to an XMLHttpRequest.


Here the javascript code :


var xhr = new XMLHttpRequest();
xhr.open('GET', "http://localhost:8080", true);
xhr.setRequestHeader('Authorization', 'Bearer hefiafizepzgenozngopzngpzegn');
xhr.send();


Here the log on my local server :


Request : /
Headers : {"host":"localhost:8080","accept":"*/","accept-language":"en-us","connection":"keep-alive","accept-encoding":"gzip, deflate","user-agent":"Test/1 CFNetwork/758.1.2 Darwin/14.5.0"}


Did I miss something ?


Thanks for your help


PS : Note that if I rename the header "X-Authorization" it works.

Answered by in 57467022
Accepted Answer

Always read the doc ... Sorry


I never had problems using the Authorization header before. Is it a new restriction ? Well I will find a way around


Thank you for your answer !

I am having the same exact issue. This isn't an issue on any other platform, I executed on Chrome just fine.


Anyone have a workaround???

I submitted a bug to apple regarding this because I don't see a way around it without some hacky changes to my API.

This bug has been fixed as of tvOS Beta 3!


Thanks Apple for listening and getting this working!

Could you please take a look at this issue with responseType for the XHR?
https://forums.developer.apple.com/thread/26643
Thank you.

Is this confirmed? Can I modify the Authorization header?


The documentation hasn't changed.

This is confirmed, the Authorization header is not restricted anymore as I am able to call all my APIs with the Authorization header and it seems to be working fine 🙂

XMLHttpRequest / Authorization Header
 
 
Q