Linux curl命令详解 用法指南

555次阅读
没有评论

curl 是常用的命令行工具,用来请求 Web 服务器。它的名字就是客户端(client)的 URL 工具的意思。

不带有任何参数时,curl 就是发出 GET 请求,服务器返回的内容会在命令行输出

curl https://www.example.com

-A

参数指定客户端的用户代理标头,即User-Agent。curl 的默认用户代理字符串是curl/[version]

#客户端chrome浏览器
curl -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36' https://google.com

-H

参数直接指定标头,可以更改User-Agent,(CF DDNS)

curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$CFZONE_ID/dns_records/$CFRECORD_ID" \
  -H "X-Auth-Email: $CFUSER" \
  -H "X-Auth-Key: $CFKEY" \
  -H "Content-Type: application/json" \
  --data "{\"id\":\"$CFZONE_ID\",\"type\":\"$CFRECORD_TYPE\",\"name\":\"$CFRECORD_NAME\",\"content\":\"$WAN_IP\", \"ttl\":$CFTTL}")
#添加多个请求头内容
curl -H 'Accept-Language: en-US' -H 'Secret-Message: xyzzy' https://google.com

-b

设置cookie

curl -b 'foo=bar;foo2=bar' https://google.com
#文件形式读取cookie
curl -b cookies.txt https://www.google.com

-c

参数将服务器设置的 Cookie 写入一个文件。

curl -c cookies.txt https://www.google.com

-d

参数用于发送 POST 请求的数据体,使用-d,无需再使用-X

设定 http body 默认使用请求标头 content-type application/x-www-form-urlencoded (H)

curl -d'login=name&password=123'-X POST https://google.com/login
#配置文件形式
curl -d '@data.txt' https://google.com/login

-X

使用指定的 http method 例如 -X POST

-e

参数用来设置 HTTP 的标头Referer,表示请求的来源

curl -e 'https://google.com?q=example' https://www.example.com

-o

响应保存成文件

curl -o example.html https://www.example.com

-O

#参数将服务器回应保存成文件,并将 URL 的最后部分当作文件名。
curl -O https://www.example.com/foo/cat.html
#服务器回应保存成文件,文件名为cat.html

-s -S

s,不输出任何错误或进度,S,输出,与-o连用

-u

-v

参数输出通信的整个过程,用于调试。

curl -v https://www.maobuni.com

-x

指定 HTTP 请求的代理。

curl -x socks5://name:[email protected]:8080 https://www.example.com
#地址myproxy.com:8080
#指定用户名和密码
#代理协议socks5
curl -x name:[email protected]:8080 https://www.example.com
#不指定默认http代理协议

用到即更新(https://www.jianshu.com/p/07c4dddae43a

正文完
 
评论(没有评论)