我正在使用jQuery为每个AJAX请求发送自定义标头。
$.ajaxSetup({
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + btoa(user + ":" + sessionID));
},
});
我希望能够读取Node.js应用程序上的标题。
这就是我在做的事情:
http.createServer(function (req, resp) {
console.log(req.headers);
........
输出像我这样的标题:
{ host: 'localhost:9000',
connection: 'keep-alive',
'access-control-request-method': 'GET'
origin: 'http://localhost',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
'access-control-request-headers': 'authorization',
accept: '*/*',
'accept-encoding': 'gzip, deflate, br'
'accept-language': 'en-US,en;q=0.9' }
我期待看到我的授权标题的值。我该怎么做才能得到它?
答案 0 :(得分:0)
答案 1 :(得分:0)
尝试这个例子:
$.ajax({
xhrFields: {
withCredentials: true
},
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Basic ' + btoa('user + ":" + sessionID'));
},
url: "YOUR URL NODEJS"
});