curl 命令速查
基本请求
发送 GET 请求
curl https://example.com常用参数:
-i:显示响应头。-L:跟随重定向。-v:输出详细连接过程,适合排查 TLS、代理、Header。
发送 JSON
Scenario
调用 JSON API
设置 Content-Type,用 -d 发送请求体。curl 使用 -d 时默认会改成 POST。
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name":"Oceanz"}'携带 Header
curl https://api.example.com/me \
-H "Authorization: Bearer <token>" \
-H "Accept: application/json"下载文件
curl -L -o output.zip https://example.com/file.zip-o output.zip:指定保存文件名。-O:使用远程文件名保存。-C -:断点续传。