最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to convert a curl command to fetch()? - Stack Overflow

programmeradmin3浏览0评论

Here is my mand:

curl -H 'API-Key: EXAMPLE'  --data 'SUBID=576965' --data 'label=example'

I have tried

fetch(";, {
    method: "POST",
    headers: {
        "API-Key":"EXAMPLE"
    },
    data: "SUBID=576965&label=example",
})

and many others, but none of them worked.

Here is my mand:

curl -H 'API-Key: EXAMPLE' https://api.vultr./v1/server/label_set --data 'SUBID=576965' --data 'label=example'

I have tried

fetch("https://api.vultr./v1/server/label_set", {
    method: "POST",
    headers: {
        "API-Key":"EXAMPLE"
    },
    data: "SUBID=576965&label=example",
})

and many others, but none of them worked.

Share Improve this question edited Sep 7, 2022 at 8:39 user3064538 asked Jun 22, 2016 at 13:41 Zhaoyu ZHONGZhaoyu ZHONG 1331 gold badge1 silver badge9 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 11

You could try this tool: https://kigiri.github.io/fetch/

Source on github: https://github./kigiri/fetch

Output:

fetch("https://api.vultr./v1/server/label_set", {
       body: "SUBID=576965&label=example",
       header: {
       "API-Key": "EXAMPLE",
       "Content-Type": "application/x-www-form-urlencoded"
   }
})

You can use curlconverter./javascript/. It converts your mand to

fetch('https://api.vultr./v1/server/label_set', {
    method: 'POST',
    headers: {
        'API-Key': 'EXAMPLE'
    },
    body: new URLSearchParams({
        'SUBID': '576965',
        'label': 'example'
    })
});
发布评论

评论列表(0)

  1. 暂无评论