[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"menus-public":3,"blog-10036":83,"blog-10036-comments":92},[4,15,43,66],{"id":5,"title":6,"link":7,"icon":8,"target":9,"sort_order":10,"is_active":11,"parent_id":12,"created_at":13,"children":14},10001,"首页","\u002F","","_blank",0,true,null,"2026-04-04T12:03:45",[],{"id":16,"title":17,"link":18,"icon":8,"target":19,"sort_order":20,"is_active":11,"parent_id":12,"created_at":21,"children":22},10038,"墨言博客","\u002Fblog","_self",1,"2026-10-30T23:08:14",[23,29,36],{"id":24,"title":25,"link":26,"icon":8,"target":19,"sort_order":20,"is_active":11,"parent_id":16,"created_at":27,"children":28},10039,"技术前沿","\u002Fblog?category=10001","2026-10-30T23:10:46",[],{"id":30,"title":31,"link":32,"icon":8,"target":19,"sort_order":33,"is_active":11,"parent_id":16,"created_at":34,"children":35},10042,"生活随笔","\u002Fblog?category=20007",2,"2026-10-30T23:55:19",[],{"id":37,"title":38,"link":39,"icon":8,"target":19,"sort_order":40,"is_active":11,"parent_id":16,"created_at":41,"children":42},10043,"旅游日记","\u002Fblog?category=20006",3,"2026-10-31T00:00:11",[],{"id":33,"title":44,"link":45,"icon":8,"target":19,"sort_order":33,"is_active":11,"parent_id":12,"created_at":46,"children":47},"新闻中心","\u002Fnews","2026-10-24T19:09:40",[48,54,60],{"id":49,"title":50,"link":51,"icon":8,"target":19,"sort_order":20,"is_active":11,"parent_id":33,"created_at":52,"children":53},10046,"产品动态","\u002Fnews?category=20010","2026-10-31T00:17:38",[],{"id":55,"title":56,"link":57,"icon":8,"target":19,"sort_order":33,"is_active":11,"parent_id":33,"created_at":58,"children":59},10047,"新闻热点","\u002Fnews?category=20009","2026-10-31T00:17:55",[],{"id":61,"title":62,"link":63,"icon":8,"target":19,"sort_order":40,"is_active":11,"parent_id":33,"created_at":64,"children":65},10045,"公司动态","\u002Fnews?category=20008","2026-10-31T00:17:11",[],{"id":67,"title":68,"link":69,"icon":8,"target":19,"sort_order":67,"is_active":11,"parent_id":12,"created_at":46,"children":70},4,"精彩视频","\u002Fvideo",[71,77],{"id":72,"title":73,"link":74,"icon":8,"target":19,"sort_order":10,"is_active":11,"parent_id":67,"created_at":75,"children":76},13,"活动记录","\u002Fvideo?category=6","2026-10-25T21:04:39",[],{"id":78,"title":79,"link":80,"icon":8,"target":19,"sort_order":20,"is_active":11,"parent_id":67,"created_at":81,"children":82},11,"产品展示","\u002Fvideo?category=5","2026-10-25T21:02:59",[],{"id":84,"category_id":5,"title":85,"author":8,"summary":86,"cover":87,"content":88,"tags":8,"seo_title":8,"seo_description":8,"seo_keywords":8,"og_image":8,"views":89,"comment_count":10,"is_top":90,"is_published":11,"created_at":91},10036,"Curl命令使用","curl 是一款跨平台命令行工具，用于网络数据传输，支持 HTTP\u002FHTTPS、FTP、SFTP 等协议，常用于接口调试、爬虫、文件上传下载、自动化脚本。Windows10+\u002FMac\u002FLinux 自带。","\u002Fstatic\u002Fuploads\u002Fblogs\u002F1792160711919-554183248.png","# curl 使用教程\n\ncurl（Client URL）是一个命令行工具，用于通过各种协议（HTTP、HTTPS、FTP 等）传输数据。它是调试 API、下载文件、测试接口的利器。\n\n## 目录\n\n- [基本语法](#基本语法)\n- [发送 GET 请求](#发送GET请求)\n- [发送 POST 请求](#发送POST请求)\n- [设置请求头](#设置请求头)\n- [处理响应](#处理响应)\n- [下载与上传文件](#下载与上传文件)\n- [认证](#认证)\n- [常用选项速查](#常用选项速查)\n- [实战示例](#实战示例)\n\n## 基本语法\n\n```bash\ncurl [选项] [URL]\n```\n\n不带任何选项时，curl 默认发送 GET 请求并把响应体打印到终端：\n\n```bash\ncurl https:\u002F\u002Fapi.example.com\u002Fusers\n```\n\n## 发送GET请求 \n\n### 带查询参数\n\n```bash\ncurl \"https:\u002F\u002Fapi.example.com\u002Fusers?page=1&limit=10\"\n```\n\n也可以用 `--data-urlencode` 配合 `-G` 自动编码参数：\n\n```bash\ncurl -G https:\u002F\u002Fapi.example.com\u002Fsearch \\\n  --data-urlencode \"q=hello world\" \\\n  --data-urlencode \"lang=zh\"\n```\n\n### 跟随重定向\n\n默认不跟随 301\u002F302 重定向，加 `-L` 即可：\n\n```bash\ncurl -L https:\u002F\u002Fexample.com\u002Fredirect\n```\n\n## 发送POST请求\n\n### 提交 JSON 数据\n\n```bash\ncurl -X POST https:\u002F\u002Fapi.example.com\u002Fusers \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"name\": \"张三\", \"age\": 28}'\n```\n\n`-d` 会自动使用 POST 方法，因此 `-X POST` 可省略。\n\n### 提交表单数据\n\n```bash\ncurl -X POST https:\u002F\u002Fapi.example.com\u002Flogin \\\n  -d \"username=admin\" \\\n  -d \"password=123456\"\n```\n\n### 从文件读取请求体\n\n```bash\ncurl -X POST https:\u002F\u002Fapi.example.com\u002Fusers \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d @data.json\n```\n\n### 其他 HTTP 方法\n\n```bash\ncurl -X PUT    https:\u002F\u002Fapi.example.com\u002Fusers\u002F1 -d '{\"age\": 29}'\ncurl -X PATCH  https:\u002F\u002Fapi.example.com\u002Fusers\u002F1 -d '{\"age\": 30}'\ncurl -X DELETE https:\u002F\u002Fapi.example.com\u002Fusers\u002F1\n```\n\n## 设置请求头\n\n使用 `-H` 添加请求头，可多次使用：\n\n```bash\ncurl https:\u002F\u002Fapi.example.com\u002Fusers \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -H \"Accept: application\u002Fjson\" \\\n  -H \"Authorization: Bearer your-token-here\" \\\n  -H \"User-Agent: MyApp\u002F1.0\"\n```\n\n## 处理响应\n\n### 查看响应头\n\n```bash\n# 同时显示响应头和响应体\ncurl -i https:\u002F\u002Fapi.example.com\n\n# 只看响应头（相当于发 HEAD 请求）\ncurl -I https:\u002F\u002Fapi.example.com\n```\n\n### 保存响应到文件\n\n```bash\ncurl -o output.json https:\u002F\u002Fapi.example.com\u002Fusers\n```\n\n### 显示详细过程（调试）\n\n```bash\ncurl -v https:\u002F\u002Fapi.example.com\n```\n\n### 只显示错误信息\n\n```bash\ncurl -sS https:\u002F\u002Fapi.example.com\n```\n\n### 格式化输出（配合 jq）\n\n```bash\ncurl -s https:\u002F\u002Fapi.example.com\u002Fusers | jq .\n```\n\n### 查看请求耗时等统计信息\n\n```bash\ncurl -o \u002Fdev\u002Fnull -s -w \"HTTP状态码: %{http_code}\\n总耗时: %{time_total}s\\n下载速度: %{speed_download} B\u002Fs\\n\" \\\n  https:\u002F\u002Fapi.example.com\n```\n\n## 下载与上传文件\n\n### 下载文件\n\n```bash\n# 保存为指定文件名\ncurl -o myfile.zip https:\u002F\u002Fexample.com\u002Ffile.zip\n\n# 使用服务器上的原始文件名\ncurl -O https:\u002F\u002Fexample.com\u002Ffile.zip\n\n# 断点续传\ncurl -C - -O https:\u002F\u002Fexample.com\u002Fbigfile.zip\n\n# 限制下载速度（100KB\u002Fs）\ncurl --limit-rate 100k -O https:\u002F\u002Fexample.com\u002Ffile.zip\n```\n\n### 上传文件（multipart 表单）\n\n```bash\ncurl -X POST https:\u002F\u002Fapi.example.com\u002Fupload \\\n  -F \"file=@\u002Fpath\u002Fto\u002Fphoto.jpg\" \\\n  -F \"description=我的照片\"\n```\n\n### 上传文件（PUT 二进制）\n\n```bash\ncurl -X PUT https:\u002F\u002Fapi.example.com\u002Ffiles\u002Fphoto.jpg \\\n  -H \"Content-Type: image\u002Fjpeg\" \\\n  --data-binary @\u002Fpath\u002Fto\u002Fphoto.jpg\n```\n\n## 认证\n\n### Basic Auth\n\n```bash\ncurl -u username:password https:\u002F\u002Fapi.example.com\u002Fprivate\n```\n\n### Bearer Token\n\n```bash\ncurl -H \"Authorization: Bearer eyJhbGciOi...\" https:\u002F\u002Fapi.example.com\u002Fprivate\n```\n\n### Cookie\n\n```bash\n# 发送 Cookie\ncurl -b \"session_id=abc123\" https:\u002F\u002Fapi.example.com\n\n# 从文件读取 Cookie\ncurl -b cookies.txt https:\u002F\u002Fapi.example.com\n\n# 保存服务端返回的 Cookie\ncurl -c cookies.txt https:\u002F\u002Fexample.com\u002Flogin\n```\n\n### 忽略 SSL 证书验证（仅用于测试）\n\n```bash\ncurl -k https:\u002F\u002Fself-signed.example.com\n```\n\n## 常用选项速查\n\n| 选项 | 说明 |\n| ---- | ---- |\n| `-X \u003C方法>` | 指定 HTTP 方法（GET\u002FPOST\u002FPUT\u002FDELETE 等） |\n| `-H \u003C头>` | 添加请求头 |\n| `-d \u003C数据>` | 发送请求体数据（自动用 POST） |\n| `-F \u003C字段>` | 以 multipart\u002Fform-data 形式提交 |\n| `-o \u003C文件>` | 输出保存到指定文件 |\n| `-O` | 以远端文件名保存 |\n| `-L` | 跟随重定向 |\n| `-i` | 输出包含响应头 |\n| `-I` | 只获取响应头 |\n| `-v` | 显示详细调试信息 |\n| `-s` | 静默模式 |\n| `-S` | 静默模式下仍显示错误 |\n| `-k` | 忽略 SSL 证书校验 |\n| `-u \u003C用户:密码>` | Basic 认证 |\n| `-b \u003Ccookie>` | 发送 Cookie |\n| `-c \u003C文件>` | 保存 Cookie 到文件 |\n| `-C -` | 断点续传 |\n| `--proxy \u003C地址>` | 使用代理 |\n| `--max-time \u003C秒>` | 设置超时时间 |\n\n## 实战示例\n\n### 1. 测试本地 API 是否存活\n\n```bash\ncurl -s -o \u002Fdev\u002Fnull -w \"%{http_code}\" http:\u002F\u002Flocalhost:3000\u002Fhealth\n```\n\n### 2. 登录并保存 Cookie，再访问受保护页面\n\n```bash\n# 登录\ncurl -c cookies.txt -X POST https:\u002F\u002Fexample.com\u002Flogin \\\n  -d \"username=admin&password=123456\"\n\n# 携带 Cookie 访问\ncurl -b cookies.txt https:\u002F\u002Fexample.com\u002Fdashboard\n```\n\n### 3. 调用 GitHub API 获取用户信息\n\n```bash\ncurl -s https:\u002F\u002Fapi.github.com\u002Fusers\u002Foctocat \\\n  -H \"Accept: application\u002Fvnd.github+json\" | jq .name\n```\n\n### 4. 通过代理访问\n\n```bash\ncurl -x http:\u002F\u002F127.0.0.1:7890 https:\u002F\u002Fapi.example.com\n```\n\n### 5. 模拟慢速网络下的超时控制\n\n```bash\ncurl --connect-timeout 5 --max-time 30 https:\u002F\u002Fapi.example.com\n```\n\n### 6. 将浏览器请求复制为 curl\n\n在 Chrome\u002FEdge 开发者工具中：Network 面板 → 右键请求 → Copy → Copy as cURL，可直接粘贴到终端重放请求。\n\n---\n\n> 提示：Windows 10 1803 之后系统自带 curl；macOS 和大多数 Linux 发行版也默认安装。输入 `curl --version` 可查看版本信息。",33,false,"2026-10-18T15:05:20",{"list":93,"total":10,"page":20,"size":94},[],30]