【问题标题】:Axios Bad Request 400 PostAxios 错误请求 400 发布
【发布时间】:2020-11-19 13:09:12
【问题描述】:
const headers = {
    Authorization: 'Bearer fui3h73bjflkbf-hdug37o8' 
}
const body = { "name": "example.com", "account": { "id": "72672yhhuo2nu2" }, "jump_start": true, "type": "full" }


let url = 'https://api.cloudflare.com/client/v4/zones'
axios.post( 
    url,
    body,
    headers
  ).then(console.log).catch(console.log);

有什么可以帮助我的吗?我不断收到来自 Axios 的 400 错误请求 - 我可以通过 GET 请求传递相同的令牌并确认其工作正常

【问题讨论】:

    标签: javascript axios


    【解决方案1】:

    正在格式化

    var config = {
        headers: {'Authorization': "Bearer fui3h73bjflkbf-hdug37o8"}
    };
    

    【讨论】:

      【解决方案2】:

      您使用什么来检查响应?这是请求的正文:

      {
          "success": false,
          "errors": [
              {
                  "code": 6003,
                  "message": "Invalid request headers",
                  "error_chain": [
                      {
                          "code": 6111,
                          "message": "Invalid format for Authorization header"
                      }
                  ]
              }
          ],
          "messages": [],
          "result": null
      }
      

      所以问题是您发送了错误的令牌。检查是否正确。 您可以使用 cloudflare 网站上的“Bearer YQSn-xWAQiiEh9qM58wZNnyQS7FUdoqGIUAbrh7T”来检查您是否会得到 403 Forbidden 而不是当前的 400。如果是,您的请求很好,您只需要正确的令牌。

      【讨论】:

      • 所以我假设返回 403,因为我也使用了错误的帐户 ID 来发布
      • 绝对!但这也意味着您的代码可以正常工作。所以唯一的问题是不正确的令牌'Bearer fui3h73bjflkbf-hdug37o8'
      • 所以奇怪的是,我可以将相同的信息扔给邮递员,而且效果很好。根据 API 指南确认对令牌的权限。我一直在想我以某种他们不期望的格式通过了授权
      猜你喜欢
      • 2021-03-31
      • 1970-01-01
      • 2018-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-30
      • 2020-02-16
      • 2020-05-08
      相关资源
      最近更新 更多