curl 的用法

简介

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

模拟请求

curl https://www.example.com

  • -A 指定客户端的用户代理标头,即 User-Agent 。curl 的默认用户代理字符串是 curl/[version]
    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://www.example.com
  • -b 用来向服务器发送 cookie
    curl -b 'fool=barl;foo2=bar2' https://www.example.com
  • -c 将服务器设置的 Cookie 写入一个文件
    curl -c cookies.txt https://www.example.com
  • -d 用于发送 POSt 请求的数据体
    curl -d 'login=emma&password=123' -X POST https://www.example.com
  • --date-urlencode 等同于 -d,发送 POST 请求的数据体,区别在于会自动将发送的数据进行 URL 编码
    curl --date-urlencode 'comment=hello world' https://www.example.com
  • -e 用来设置 HTTP 的标头 Referer ,表示请求的来源
    curl -e 'https://www.origin.com' https://www.example.com
  • -F 用来向服务器上传二进制文件
    curl -F 'file=@example.png' https://www.example.com
原文地址:https://www.cnblogs.com/zhuozhang/p/15356345.html