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


The following functions work in IE, but not in Chrome:

  function doStuff ( ) {Var Requests = New XMLHttpRequest (); Request.open ("post", "http://twitter.com/statuses/update.json", true, "USERNAME-here", "password-here"); Request.send ("Status = Update Status"); }  

Chrome generates the following request Note: The authorization header is unavailable:

 Options /statuses/update.json HTTP / 1.1 Host: twitter.com Connection: Keep -Janda User-Agent: Mozilla / 5.0 (Windows; U; Windows NT 6.1; N-US) Apple WebKat / 532.5 (KHML, like GECO) Chrome / 4.0.249.78 Safari / 532.5 Access-Control-Request-Method: Post Origination : File: // Access-Control-Request-Header: Accept Content-Type: * / * Accept-En Oding: gzip, deflate, sdch acceptance-language: en-US, en; Q = 0.8 Accept-charset: ISO-885 9-1, UTF-8; Q = 0.7, *; Q = 0.3  

I get the following response (http 401):

 HTTP / 1.1 401 Unauthorized date: Wednesday, 03 Feb 2010 00:39:33 GMT Server: hi Status: 401 Unauthorized WWW-certify: Original realm = "Twitter API" X-Runtime: 0.00107 Content-Type: Application / Jason; charset = utf-8 Cache-Control: no-cache, max-age = 300 set cookies: _twitter_sess = BAh7BzoHaWQiJTUxMTc2Nzk4N2U0YzMzZmU0ZTQyNzI4NjQyYjI3ODE2Igpm% 250AbGFzaElDOidBY3Rpb25Db250cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNoewAG% 250AOgpAdXNlZHsA - bb61324c3ba12c3cd1794b3895a906a69c154edd; Domain = .twitter.com; Path = / End: Wed, 03 Feb 2010 00:44:33 GMT Miscellaneous: Accept-encoding content-length: 73 Connections: Close {"Request": "/ statuses / update.json", "Error": " Could not prove you. "} 

So, how should I pass the XHR username and password? WebKit / Safari documentation says that these parameters should be taken in the open method, so I'm not sure why this is unsuccessful.

By looking at it, you are trying to do an X-Domain XMLHTTPRequest, which is why Chrome Options sends pre-flight requests. Because the Twitter server does not respond to option requests, because it indicates that X-Domain access is OK, you get a failure here.

Your code will only work in IE in the local computer zone or if you turn off x-domain-checking (very dangerous)


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -