简体   繁体   English

如何在Node.js中添加承载令牌以请求发布方法?

[英]How to add Bearer token to requestify post method in nodejs?

How can i pass Bearer token with post method. 我如何通过post方法传递Bearer令牌。 I tried with postman but getting this response "Error: Unauthorized Access. Request is not authorized" 我尝试使用邮递员,但收到此响应“错误:未经授权的访问。请求未经授权”

            await turnContext.sendActivity(`${await requestify.request(url, {
                method: 'POST',
                body: data,
                dataType: 'json',
                auth:{
                    "Bearer":access_token // token
                }
            }).then(async function (res) {
                console.log(res.body);
                return res.body;
            })}`);

You need to add Bearer as prefix to your token: 您需要将Bearer作为前缀添加到令牌中:

 await turnContext.sendActivity(`${await requestify.request(url, {
                method: 'POST',
                body: data,
                dataType: 'json',
                auth:{
                    `Bearer ${access_token}` // token
                }
            }).then(async function (res) {
                console.log(res.body);
                return res.body;
            })}`);

Looking at the documentation the auth property is used for basic auth only, so just add the Authorization header manually 查看文档auth属性仅用于基本身份验证,因此只需手动添加Authorization标头

await requestify.request(url, {
    method: 'POST',
    body: data,
    dataType: 'json',
    headers :{
        Authorization:"Bearer " + access_token // token
    }
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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