curl

curl

Example

 # include http response headers in output
curl -i 'example.com'

# Send post request with payload
curl -X POST -d 'a=1&b=2' 'http://example.com/'

# -H set request http reader
curl -X POST -H "Content-Type: application/json" -d '{"a": 1}' 'http://example.com/'

# 手工指定 URL 里域名解析的地址。可用于测试反向代理/回源/cloudflare
curl -k --resolve sakura-paris.org:443:1.2.3.4 https://sakura-paris.org/

# 使用代理
curl -I https://ipinfo.io -x http://127.0.0.1:1080

#  follow Redirect; download file as it's remote name
curl -L -O https://example.com/file.rar

参数

  • -I : 仅输出 response 的 headers 而不输出 response body。注意如果使用这个参赛,默认会使用 OPTION 方法(而非 GET)连接服务器,除非同时指定 -X GET 参数。
  • -i : 在输出里包含 response headers。
  • -x http://127.0.0.1:1080 : 使用代理连接。代理协议包括: "socks5://", "http://"。(注:也可以使用 http_proxy, HTTPS_PROXY, ALL_PROXY 等环境变量设定访问某种协议url时使用的代理。)
  • -u "username:password" : 登录用户名/密码。http base authentication
  • -L : follow URL rediretion (3xx).
  • -n : 使用 ~/.netrc 作为网站用户名/密码. ~/.netrc 文件保存当前用户的网站登录信息,每行一个域名:

machine example.com login USERNAME password PASSWORD

FTP 上传文件

默认 passive 模式

curl -T test.txt ftp://username:password@ftp.server.com/backup/

主动模式:

curl -P - -T test.txt ftp://username:password@ftp.server.com/backup/


Last update: 2022-05-10 07:29:05 UTC