cURL 转代码 — cURL 转 fetch、Python、Go、PHP
在线将 cURL 命令转换为 fetch、Node、Python requests、Go、PHP 和 axios 代码,并解析方法、参数、请求头、Cookie 和请求体。
cURL 命令
请求
POSThttps://api.example.com/v1/orders
查询参数
2
- expand
- items
- limit
- 20
请求头
2
- Content-Type
- application/json
- Authorization
- Bearer demo_7f3a9c2e41
Cookie
2
- session
- 7d1f0c
- theme
- dark
请求体
JSON
{
"customer": "cus_42",
"items": [
{
"sku": "KB-75",
"qty": 1
}
],
"note": "It's a gift"
}选项
压缩(--compressed)
// Browsers drop forbidden headers (Cookie, Host, Referer…).
// For cookies, use credentials: "include" instead.
// Browser manual redirects return an opaque response; the 3xx status and body are unavailable.
const response = await fetch("https://api.example.com/v1/orders?expand=items&limit=20", {
redirect: "manual",
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer demo_7f3a9c2e41",
"Cookie": "session=7d1f0c; theme=dark"
},
body: JSON.stringify({
"customer": "cus_42",
"items": [
{
"sku": "KB-75",
"qty": 1
}
],
"note": "It's a gift"
})
});
console.log(response.status, await response.text());POST · 25 行 · 警告:0不会发送任何请求
在浏览器中运行。命令只会被解析,不会执行,也不会发出任何请求。
相关工具
格式参考资料
工具页面更新日期: