我嘗試使用ajax(xmlHttpRequest)來使用WCF服務(REST)。該服務需要基本身份驗證。Ajax回調無法找到授權標頭
我的Ajax調用:
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
//do some stuff
}
}
};
httpRequest.open('PUT', 'http://localhost:59000/v1/users/1', true, 'user1', 'user1');
httpRequest.withCredentials = "true";
//must authenticate both..in open() but also set header manually ...cf http://stackoverflow.com/questions/1358550/xmlhttp-request-basic-authentication-issue
httpRequest.setRequestHeader('Auhtorization', 'Basic user1:user1');
httpRequest.setRequestHeader('Accept', 'application/json');
// overridemimeType() does not set content type header .... don't know why ?
httpRequest.setRequestHeader('Content-Type', 'application/json');
var params = { "UserName": "user1" };
var requestBodyString = JSON.stringify(params);
httpRequest.send(requestBodyString);
我第一次處理在服務器端請求的方式如下
我的瀏覽器發送我的錯誤「請求頭字段Auhtorization不由Access-Control-Allow-Headers控制「,但正如你所看到的,它在響應頭部變成白色。
此外,當我嘗試與提琴手一切都很好,我甚至允許標題虛擬一個。
所以我真的很困惑,如果有人可以幫忙,請做!
感謝
您正在使用哪種瀏覽器? – VJAI
谷歌瀏覽器! – laurent