我需要访问服务器端(Node)中的axios标头授权令牌,显示未定义。请帮助..节点服务器无法检索反应axios请求标头参数的值
客户端(反应)要求:
var config = {
headers: {
'cache-control':'no-cache',
'content-type': 'application/x-www-form-urlencoded',
'authorization' :'bearer '+Auth.getToken()
}
};
axios.get(ApiConfig.API_BASE+'api/admin/profile/', config).then(function(response) {
this.setState({status:'success', profile: response.data.data});
}).catch(function(response) {
console.log(response);
});
服务器端(节点):
module.exports = (req, res, next) => {
console.log(req.headers.authorization);
if(!req.headers.authorization) {
return res.status(401).end();
}
};
日志显示不明确的。我还安慰了整个头部,但它们的输出是:
{ host: 'localhost:8027',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0',
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'accept-language': 'en-US,en;q=0.5',
'accept-encoding': 'gzip, deflate',
'access-control-request-method': 'GET',
'access-control-request-headers': 'authorization,cache-control',
origin: 'http://localhost:3001',
connection: 'keep-alive' }
如何获取授权令牌值?
谢谢。
[如何从请求中使用NodeJS连接提取请求http头]可能的重复(https://stackoverflow.com/questions/13147693/how-to-extract-request-http-headers-from-a-request -using-nodejs-connect) – mersocarlin