【问题标题】:"Authorization require" even though I specified Authorization“需要授权”,即使我指定了授权
【发布时间】: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" +
            "]"
}

当我打印出实际的 ma​​ilOpt 时,我得到了以下信息。一切看起来都很好。

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


    【解决方案1】:

    在您的选项中,您拥有header 属性,但它应该是headers,这就是"Authorization" 部分被忽略的原因。

    另外,不确定uri 是否是有效属性,但url 肯定是。

    【讨论】:

      猜你喜欢
      • 2015-10-29
      • 2019-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多