【发布时间】:2018-01-23 22:57:50
【问题描述】:
在下面的代码中,我为 API 的 OAuth2 指定了 Authorization with Bearer。但我不断收到401 - authorization required。我不知道为什么身份验证不起作用,我大摇大摆地尝试了它,爪子但一切都起作用了,但在 Node 端却没有。
let mailOpt = {
uri: "https://api.sendgrid.com/v3/contactdb/recipients",
method: "POST",
header: {
"Authorization": `Bearer ${account.SENDGRID_ACCESS_TOKEN}`
},
body: "[\n" +
" {\n" +
` \"email\": \"${response[0].email}\"\n` +
" }\n" +
"]"
}
当我打印出实际的 mailOpt 时,我得到了以下信息。一切看起来都很好。
MAILopt { uri: 'https://api.sendgrid.com/v3/contactdb/recipients',
method: 'POST',
header:
{ Authorization: 'Bearer access_token' },
body: '[\n {\n "email": "voqes@inboxbear.com"\n }\n]' }
【问题讨论】:
标签: node.js http sendgrid node-request sendgrid-api-v3