简体   繁体   中英

Get request headers in azure functions NodeJs Http Trigger

How do I get the request headers in Azure functions ? I use JavaScript http trigger to handle a request. I need to read some token sent in the request header from the front end. How can I do this ?

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

Use req.headers , eg

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

In case anyone wants the C#:

eg To get the Authorization token:

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

More on the various headers here .

You can also do something like this with the run time context also.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM