admin管理员组文章数量:1224990
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();
};
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();
};
Share
Improve this question
edited Dec 19, 2017 at 16:33
Jewel Lukose
asked Dec 19, 2017 at 15:54
Jewel LukoseJewel Lukose
701 gold badge1 silver badge7 bronze badges
1
- can you post your code so we can look at it and help you out? – hjm Commented Dec 19, 2017 at 15:56
4 Answers
Reset to default 9Use req.headers
, e.g.
module.exports = function (context, req) {
context.log('Header: ' + req.headers['user-agent']);
context.done();
};
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();
};
For those reading this in 2025, using Azure Function model v4 and NodeJS 18: request.headers
currently returns an object with a javascript Map, the latter containing the headers list. To get the "Authorization" header value, use the Map.get() method: request.headers.get('Authorization')
In case anyone wants the C#:
e.g. To get the Authorization token:
log.Info(req.Headers.Authorization.Token.ToString());
More on the various headers here.
本文标签: javascriptGet request headers in azure functions NodeJs Http TriggerStack Overflow
版权声明:本文标题:javascript - Get request headers in azure functions NodeJs Http Trigger - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739398974a2161524.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论