cURL Builder

One input per line. Output is numbered to match the input order.
Pinned tools are listed in your favourites on the home page.Copies a link to this tool that carries your current input, so it opens ready to run.Gives you an iframe snippet for putting this tool on your own site.
Ctrl+Enter Run  · Ctrl+Shift+C Copy  · Esc Clear

Understand cURL Builder

由 URL、方法、请求头、请求体和认证信息构建可直接运行的 curl 命令,以及等价的 JavaScript fetch() 调用。

How it works

命令由各个参数拼装而成,而不是自由文本:`-X` 设置方法,每个头各自成为一个 `-H`,`-d` 提供请求体,`-u` 提供 Basic 凭据,`-L` 跟随跳转。各个值都用单引号包裹,请求体中的单引号会被转义为 `'\''`,这是在 POSIX shell 字符串中嵌入单引号的唯一安全写法。如果你提供了请求体却没给 Content-Type,工具会替你补上——请求体以 `{` 或 `[` 开头时补 application/json,否则补 text/plain——因为否则 curl 会默认使用 application/x-www-form-urlencoded,导致服务器误读你的 JSON。工具不会发送任何请求;它只产出文本。

When to use it

  • 把你在表单里设计好的请求,变成可以粘进终端、CI 任务或缺陷报告的命令
  • 为工单产出可复现的一行命令,用 curl 命令描述一个请求是最没有歧义的方式
  • 得到已填好请求头和请求体的 fetch() 骨架,直接粘进应用代码
  • 在 README 中用一个真的能跑起来的复制粘贴示例来记录 API 端点

Watch out for

  • 输出中的单引号是 POSIX shell 语法。Windows 的 cmd.exe 根本不把单引号当作引号——请使用 Git Bash、WSL,或者在那里运行前先转换引号写法。
  • `-k` 会为整个请求关闭 TLS 证书校验。它是在你自己机器上调试自签名证书时用的调试参数,绝不该留在脚本里。
  • Basic 认证是 Base64,不是加密。fetch 代码片段用 btoa 对 `user:password` 编码,而任何读到该命令、shell 历史或 CI 日志的人都拿到了这个密码。
  • 生成的命令里含有你真实的令牌。粘进 issue、聊天或提交之前请先把它涂掉。

Frequently Asked Questions

如何用 curl 发送带 JSON 请求体的 POST 请求?

使用:curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' https://api.example.com/endpoint。当你选择 POST 方法、添加 Content-Type 头并粘贴 JSON 请求体时,构建器会自动生成这条命令。

如何在 curl 中添加认证头?

Bearer 令牌:-H "Authorization: Bearer YOUR_TOKEN"。Basic 认证:-u username:password(curl 会自动把它编码成 Base64 的 Authorization 头),或者 -H "Authorization: Basic BASE64_ENCODED"。构建器为两者都提供了认证区域。

如何把 curl 转换成 Python、JavaScript 或 Go 代码?

本工具会生成等价的 JavaScript fetch() 调用。对于其他语言,可以使用 curl 输出——它是最通用的 HTTP 表述形式。如果需要,curlconverter.com 这类工具能把 curl 命令转换成多种语言。

How to Use cURL Builder

  1. Paste or type your input in the input area above.
  2. The tool processes your input automatically or click Run.
  3. Copy or download the result using the action buttons.
  4. Use Ctrl+Enter to run quickly from the keyboard.