我正在尝试使用 XMLHTTPRequest 在 twitter 上获取更新.
I am attempting to use XMLHTTPRequest to get an update on twitter.
var XMLReq = new XMLHttpRequest();
XMLReq.open("GET", "http://twitter.com/account/verify_credentials.json", false, "TestAct", "password");
XMLReq.send(null);
但是,使用我的嗅探器,我看不到任何授权标头正在通过.因此,我收到了来自 Twitter 的 401 错误响应.
However, using my sniffer I cannot see any authorization headers being passed through. Hence, I get a 401 error response from Twitter.
帐号和密码输入正确.
有人尝试过吗?谁能给我一些指示?谢谢.
Anyone attempt this? Can anyone give me some pointers? Thank you.
你只需要在base64编码的字符串中添加一个Authorization header,一个用户名和密码,如下所示.
You just need to add a Authorization header, an user name and password in a base64 encoded string as follows.
XMLReq.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
这篇关于使用 XMLHTTPRequest 进行基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!