使用XMLHTTPRequest进行基本身份验证 [英] Basic Authentication With XMLHTTPRequest

查看:1336
本文介绍了使用XMLHTTPRequest进行基本身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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.

正确输入帐户和密码。

The account and password are correctly entered.

有人试图这样做吗?谁能给我一些指示?谢谢。

Anyone attempt this? Can anyone give me some pointers? Thank you.

推荐答案

您只需要在base64编码的字符串中添加Authorization标头,用户名和密码,如下所示。

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进行基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆