User authentication with XMLHttpRequest works in IE, not in Chrome? User authentication with XMLHttpRequest works in IE, not in Chrome? google-chrome google-chrome

User authentication with XMLHttpRequest works in IE, not in Chrome?


The solution was that I needed to add

request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

The way I'm doing this is... special... so this may not be of much use to others going forward. But once I added this webkit started adding Authorization.


From the look of it, you're trying to do an X-Domain XMLHTTPRequest, which is why Chrome sends the OPTIONS pre-flight request. Because the Twitter server doesn't respond to the OPTIONS request indicating that X-Domain access is okay, you get a failure here.

Your code would only work in IE in the Local Computer zone, or if you turn off x-domain-checking (very dangerous)


Have you tried:

request.setRequestHeader('Authorization', 'yourvalue');