老鬼的博客 来都来啦,那就随便看看吧~
curl常用指令
发布于: 2019-03-13 更新于: 2023-11-08 分类于:  阅读次数: 

格式

1
2
3
4
5
6
7
8
9
10
11
12
13
curl -[options] url

-A/--user-agent <string> 设置用户代理发送给服务器,即告诉服务器浏览器为什么
-basic 使用HTTP基本验证
--tcp-nodelay 使用TCP_NODELAY选项
-e/--referer <URL> 来源网址,跳转过来的网址
--cacert <file> 指定CA证书 (SSL)
--compressed 要求返回是压缩的形势,如果文件本身为一个压缩文件,则可以下载至本地
-H/--header <line>自定义头信息传递给服务器
-I/--head 只显示响应报文首部信息
--limit-rate <rate> 设置传输速度
-u/--user <user[:password]>设置服务器的用户和密码
-0/--http1.0 使用HTTP 1.0

1. 直接请求

1
curl https://jay.tohours.com

3.png

2. -A,设置用户代理发送给服务器,即可以伪装客户端身份

1
curl -A testAgent https://jay.tohours.com

4.png

3. -e,伪装 来源网址,跳转过来的网址

1
curl -e https://www.baidu.com https://jay.tohours.com

5.png

4. -i 显示http response的头信息

1
curl -i https://jay.tohours.com

6.png

5. -v 显示一次的http请求的通信过程

1
curl -v https://jay.tohours.com

7.png

6. 执行GET/POST/PUT/DELETE操作

1
2
3
4
5
curl -X GET https://jay.tohours.com
curl -X POST https://jay.tohours.com
curl -X PUT https://jay.tohours.com
curl -X DELETE https://jay.tohours.com
curl -v -X POST https://jay.tohours.com

8.png

7. -F 上传图片

1
2
curl  -i -F "file=@1.jpg" https://sit.tohours.com/salesplus/api/upload-img.action
file是名称,1.jpg是图片的值,-i是显示头信息,其中在当前运行curl的cmd路径下要能找到1.jpg的图片,否则运行会报错。

9.png

8. -H指定头信息

1
curl  -v -H "Content-Type: application/json" https://jay.tohours.com

10.png

9. -d 指定输入参数

1
curl -i -d "url=aa" url=https://a.com https://sit.tohours.com/sign/sign/url.action

11.png

10. -w 显示相应时间

1
curl -v -w %{time_connect}:%{time_starttransfer}:%{time_total}\n https://map-as-d.metlife.com.cn/eopening/api/version/add-version-log

11. 保存和携带cookie信息

1
2
3
4
5
6
7
8
curl --cookie-jar cookie.txt -i -X POST "https://jay.tohours.com/elearning/login/agent?companyCd=0986&agentCd=000000398&password=22222222&channelId=123"
cat cookie.txt

curl -b @cookie.txt --cookie-jar cookie1.txt -i -X POST "https://jay.tohours.com/elearning/login/agent?companyCd=0986&agentCd=000000398&password=22222222&channelId=123"
cat cookie1.txt

curl -b @cookie1.txt --cookie-jar cookie2.txt -i -X POST "https://jay.tohours.com/elearning/login/agent?companyCd=6&agentCd=1&password=22&channelId=123"
cat cookie2.txt
*************感谢您的阅读*************