curl工具
目录
常用参数
-A User-Agent
-A 指定User-Agent
curl https://www.baidu.com -A 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'
-H 设置headers(常用)
curl https://www.baidu.com \
-H 'user-agent:Mozilla/5.0'\
-H 'authorization: Bearer 73a3f19d-f808-45ae-b1b6-6a6fab1e90b2' \
-i 打印出服务器回应的 HTTP 标头
curl -i https://www.baidu.com
-k 参数指定跳过 SSL 检测
curl -k https://www.baidu.com
-L 跟随服务器的重定向(curl 默认不跟随重定向)
curl -L https://www.baidu.com
-o(小写)类似于wget下载
//需要指定名称
curl -o 123.jpg https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1114%2F062021132H5%2F210620132H5-1-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1659058790&t=aa289deaedb8a37b48f5c4363c694dbf
-O(大写)类似于wget下载
//默认截取路由后面url为名字,src=xxx开始截取
curl -O https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1114%2F062021132H5%2F210620132H5-1-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1659058790&t=aa289deaedb8a37b48f5c4363c694dbf
-x 指定代理ip
curl -x ip:端口 https://www.baidu.com
-X 指定请求方法
curl -X POST https://www.baidu.com
curl -X Get https://www.baidu.com
--data post带json参数
curl -X POST 'https://www.baidu.com' \
-H 'Authorization:Bearer 73a3f19d-f808-45ae-b1b6-6a6fab1e90b2' \
--data '{"page":1,"page_size":10,"bid":"","cid":"","uid":-1,"position_status":-1,"status":-1,"area":-1}' \
--compressed
--compressed压缩方式
curl -X POST 'https://www.baidu.com' \
-H 'Authorization:Bearer 73a3f19d-f808-45ae-b1b6-6a6fab1e90b2' \
--data '{"page":1,"page_size":10,"bid":"","cid":"","uid":-1,"position_status":-1,"status":-1,"area":-1}' \
--compressed
get请求
不带有任何参数时,curl 就是发出 GET 请求。
curl https://www.baidu.com
POST请求
curl -X POST 'https://www.baidu.com' \
-H 'authorization: Bearer 73a3f19d-f808-45ae-b1b6-6a6fab1e90b2' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36' \
--data '{"page":1,"page_size":10}' \
--compressed
选择了IT,必定终身学习