高级 REST 客户端(chrome 扩展)- 带参数的 GET 请求

Advanced REST client (chrome extension) - GET request with params

我正在尝试使用 header:
中的参数模拟 GET 请求 我正在使用 NodeJS,这是我的函数:

 module.exports.validate = function (req, res, db, callback) {
// if the request dosent have a header with email, reject the request
    if (!req.params.token) {
        res.writeHead(403, {
            'Content-Type': 'application/json; charset=utf-8'
        });
        res.end(JSON.stringify({
            error: "You are not authorized to access this application",
            message: "An Email is required as part of the header"
        }));
    };
    else
       {
         //do something
       }
    };

这是我的 GET 请求模拟(通过高级 REST 客户端 - chrome 扩展):

如您所见,我得到 403,因为 req.params 未定义

我的问题:如何向 header 添加参数?我插入 header 的电子邮件似乎无法正常工作。

我不确定你的 token 参数是什么,因为你没有在你的请求中发送它。但是如果你想在请求 header 中获取电子邮件,你应该使用 req.headers 而不是 req.params,像这样:

if (!req.headers.email) {
    res.writeHead(403, {
        'Content-Type': 'application/json; charset=utf-8'
    });
    res.end(JSON.stringify({
        error: "You are not authorized to access this application",
        message: "An Email is required as part of the header"
    }));
}