img

Curl基础命令总结

旁观者 1年前 ⋅ 1287 阅读

使用curl命令行进行http请求访问,常用参数总结

常用命令

-H 设置请求头 -X 设置请求方式 -d 设置参数 -b 设置cookie -i 显示返回请求头 -F 上传表单

详解:

curl http://www.baidu.com

打印返回的结果信息

1.请求类型

-X(--request) [GET,POST , PUT ...]

curl --request POST http://delpast.com

curl -X GET https://delpast.com

2.携带请求头

-H(--header) [key:value]

curl -H "access_token:123" http://delpast.com

设置cookie

-b(--cookie) [key=value/file] -c(--cookie-jar) [file]

curl -b "grafana_session=c2a070419838545d2aa19c0355032d13" http://delpast.com

等同于

curl -H "Cookie:grafana_session=c2a070419838545d2aa19c0355032d13" http://delpast.com

curl -c cookie.txt http://delpast.com

设置User-Agent

-A(--user-agent)[string]

curl -A "https://delpast.com" https://delpast.com

设置Referer

-e(--referer)[string]

curl -A "http://www.baidu.com" https://delpast.com

2.携带参数

-d(--data) [string]

curl -d "username=admin&password=123456" http://delpast.com

读取文件

curl --data "@user.txt" http://delpast.com

url编码(参数带空格等特殊处理)

curl --data-urlencode "keyword=hello world" http://delpast.com

body方式

curl -H "Content-Type: application/json" -d "{username:admin, password:123456}" http://delpast.com

3.表单提交(传文件)

-F(--form)[string]

curl -F 'file=@test.jpg;filename=ok.png;type=image/jpeg' http://delpast.com

-T(--upload-file) [file]

curl -T test.jpg https://delpast.com

4.打印相应头

-I(--head)

curl -I http://delpast.com

打印响应head和body

-i

curl -i http://delpast.com

5.其他

-k(--insecure)              跳过SSL检测
-L                          重定向跟随
--limit-rate                限制请求响应带宽
-o -O                       将响应保存为文件
-s                          不输出错误信息
-S(--show-error)            显示错误
-x(--proxy)                 使用代理

全部评论: 0

    我有话说: