Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取azure函数NodeJs Http触发器中的请求头_Javascript_Node.js_Azure_Http_Azure Functions - Fatal编程技术网

Javascript 获取azure函数NodeJs Http触发器中的请求头

Javascript 获取azure函数NodeJs Http触发器中的请求头,javascript,node.js,azure,http,azure-functions,Javascript,Node.js,Azure,Http,Azure Functions,如何在Azure函数中获取请求头?我使用JavaScript http触发器来处理请求。我需要从前端读取请求头中发送的一些令牌。我该怎么做 module.exports = function (context, req) { context.log('JavaScript HTTP trigger function processed a request.'); if (true) { context.log(req.headers['Authorization

如何在Azure函数中获取请求头?我使用JavaScript http触发器来处理请求。我需要从前端读取请求头中发送的一些令牌。我该怎么做

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();
};

使用
请求标题
,例如

module.exports = function (context, req) {
    context.log('Header: ' + req.headers['user-agent']);
    context.done();
};
如果有人想要C#:

e、 g。 要获取授权令牌,请执行以下操作:

log.Info(req.Headers.Authorization.Token.ToString());

更多关于各种标题的信息。

您也可以在运行时上下文中执行类似操作

module.exports = function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');
    context.log(context.req.headers.authorization)//You can get the pass tokens here
    context.done();
};

你能发布你的代码让我们看看并帮助你吗?非常感谢。我在文档的任何部分都找不到。请注意,标题是小写的,即
用户代理
,而不是
用户代理