简体   繁体   English

Axios 错误请求 400 发布

[英]Axios Bad Request 400 Post

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);

Can any help me with this?有什么可以帮助我的吗? I keep getting a 400 bad request from Axios - I can pass that same token over a GET request and confirm its working fine我不断收到来自 Axios 的 400 错误请求 - 我可以通过 GET 请求传递相同的令牌并确认其工作正常

What do you use to check the response?你用什么来检查响应? Here is the body of request:这是请求的正文:

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

So the problem is that you send wrong token.所以问题是你发送了错误的令牌。 Check if it is correct.检查是否正确。 You may use this one "Bearer YQSn-xWAQiiEh9qM58wZNnyQS7FUdoqGIUAbrh7T" from cloudflare site to check if you will get 403 Forbidden instead of your current 400. If so, your request is fine, and you just need correct token.您可以使用 cloudflare 网站上的“Bearer YQSn-xWAQiiEh9qM58wZNnyQS7FUdoqGIUAbrh7T”来检查您是否会获得 403 Forbidden 而不是当前的 400。如果是,您的请求很好,您只需要正确的令牌。

It was formatting正在格式化

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

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

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