ToolHub
中文
Light
GitHub
返回首页
/
开发编程
/
cURL 转 fetch / axios
加载中...
cURL 输入
加载示例
curl 'https://api.example.com/v1/projects?limit=20' -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Bearer demo-token' --data-raw '{"name":"ToolHub","private":false}' --compressed
fetch
复制
const response = await fetch("https://api.example.com/v1/projects?limit=20", { method: "POST", headers: { "Accept": "application/json", "Content-Type": "application/json", "Authorization": "Bearer demo-token", }, body: JSON.stringify({ "name": "ToolHub", "private": false }), }); const result = await response.text(); console.log(result);
axios
复制
const response = await axios({ url: "https://api.example.com/v1/projects?limit=20", method: "post", headers: { "Accept": "application/json", "Content-Type": "application/json", "Authorization": "Bearer demo-token", }, data: { "name": "ToolHub", "private": false }, }); console.log(response.data);
方法
POST
请求头
3
Body 片段
1
解析结果
https://api.example.com/v1/projects?limit=20
标记: 接受压缩, 默认 TLS