javascript - 在azure函数NodeJs Http触发器中获取请求 header

标签 javascript node.js azure http azure-functions

如何获取 Azure 函数中的请求 header ?我使用 JavaScript http 触发器来处理请求。我需要从前端读取请求 header 中发送的一些 token 。我该如何做到这一点?

module.exports = function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    if (true) {
        context.log(req.headers['Authorization'])
        context.res = {
            // status: 200, /* Defaults to 200 */
            body: "Hello there " 
        };
    }
    else {
        context.res = {
            status: 400,
            body: "Please pass a name on the query string or in the request body"
        };
    }
    context.done();
};

最佳答案

使用req.headers,例如

module.exports = function (context, req) {
    context.log('Header: ' + req.headers['user-agent']);
    context.done();
};

关于javascript - 在azure函数NodeJs Http触发器中获取请求 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47890653/

相关文章:

javascript - 触发单选按钮单击并设置选中的属性问题

javascript - 支持多个相册和评论的照片库?

javascript - 从 javascript 调用 AngularJS v1.4 函数

iphone - 通过objective-c从azure表生成身份验证 header

javascript - 如果用户在Weather Api搜索中输入了错误的城市名称,该如何使用try and catch?

javascript - 在页面加载时滚动 div 顶部,然后设置滚动正常工作

node.js - 如何使用 Jest 测试和模拟 Nodejs 函数

node.js - NodeJs 中的子进程生成输出文件和目录

c# - 将程序集加载到 WindowsAzure WorkerRole 中的单独 AppDomain 中

azure - 如何检索链接到特定提交的工作项 - Azure Devops REST API