本文介紹了使用 XMLHTTPRequest 進行基本身份驗證的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我正在嘗試使用 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);
但是,使用我的嗅探器,我看不到任何授權(quán)標頭正在通過.因此,我收到了來自 Twitter 的 401 錯誤響應(yīng).
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"));
這篇關(guān)于使用 XMLHTTPRequest 進行基本身份驗證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!