Skip to content

curl 是常用的命令行工具,用来请求 Web 服务器

curl 的用法指南

curl默认发送get请求 例如:curl www.baidu.com

可以添加参数发送post请求 例如:curl -X -POST url ,可以将两个参数合并为-XPOST , 可以简单理解默认的就是 curl -X -GET url

image-20230821231353552

使用 -d 添加请求参数 使用 -H 设置标头 例如

shell
curl -XPOST  localhost:8080/save -d '{
  "name": "test_8cd49a0fa3be",
  "age": 36
}' -H 'Content-Type:application/json'

image-20230821232910021

-I 获取头信息

shell
curl -I  localhost:8080

image-20230821233206062

-o 下载文件到当前目录,参数后面可设置文件名称

shell
curl -0 文件名 url

image-20230821233948695

--limit-rate 限制文件的下载速度,默认字节单位,不小心中断下载,可使用-C恢复下载

image-20230821235337507

使用 curl 测试网址时,大部分的会重定向,crul默认不会跟随,使用-L跟随重定向

image-20230821235827555

使用curl代理访问目标网址 curl –proxy “协议://用户名:密码@代理地址:端口” url

shell
curl --proxy "http://zs:123@127.0.0.0:7890" www.github.com