节点服务器无法读取 headers 已发送
Node server cannot read headers sent
我检查了 Chrome 开发工具并确认正在发送 X-custom headers。但出于某种原因,我无法在服务器端访问 X-custom headers。我不断收到 404 错误。任何帮助将不胜感激。
已编辑
router.get('/users', function (req, res, next) {
Console.log(req.headers['x-custom'])
if (!req.headers['x-custom']) {
return res.send(404)
}
获取请求
svc.getUser = function() {
return $http.get('/users', {
headers: {'x-custom' : this.token}
})
}
节点将 req.header
中的键小写,因此您需要检查是否存在 x-custom
属性 而不是 X-custom
:
if (!req.headers['x-custom']) {
return res.send(404)
}
我检查了 Chrome 开发工具并确认正在发送 X-custom headers。但出于某种原因,我无法在服务器端访问 X-custom headers。我不断收到 404 错误。任何帮助将不胜感激。
已编辑
router.get('/users', function (req, res, next) {
Console.log(req.headers['x-custom'])
if (!req.headers['x-custom']) {
return res.send(404)
}
获取请求
svc.getUser = function() {
return $http.get('/users', {
headers: {'x-custom' : this.token}
})
}
节点将 req.header
中的键小写,因此您需要检查是否存在 x-custom
属性 而不是 X-custom
:
if (!req.headers['x-custom']) {
return res.send(404)
}