1

如何使用 post 方法传递 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;
            })}`);
4

2 回答 2

1

您需要在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;
            })}`);
于 2019-01-03T08:31:35.770 回答
1

查看文档,该auth属性仅用于基本身份验证,因此只需手动添加 Authorization 标头

await requestify.request(url, {
    method: 'POST',
    body: data,
    dataType: 'json',
    headers :{
        Authorization:"Bearer " + access_token // token
    }
})
于 2019-01-03T08:35:04.420 回答