CURL用法
-b
-b参数用来向服务器发送 Cookie。
curl -b 'foo1=bar;foo2=bar2' https://google.com
读取本地文件cookies.txt,里面是服务器设置的 Cookie(参见-c参数),将其发送到服务器。
curl -b cookies.txt https://www.google.com
-c
-c参数将服务器设置的 Cookie 写入一个文件。
curl -c cookies.txt https://www.google.com
-d
-d参数用于发送 POST 请求的数据体(等于–data-urlencode)。HTTP 请求会自动加上标头Content-Type : application/x-www-form-urlencoded。并且会自动将请求转为 POST 方法,因此可以省略-X POST。
curl -d 'login=emma&password=123' -X POST https://google.com/login
# 或者
curl -d 'login=emma' -d 'password=123' -X POST https://google.com/login
# 读取data.txt文件的内容,作为数据体向服务器发送。
curl -d '@data.txt' https://google.com/login
-H
-H参数添加 HTTP 请求的标头。
curl -H 'Accept-Language: en-US' -H 'Secret-Message: xyzzy' https://google.com
-i
-i参数打印出服务器回应的 HTTP 标头。先输出服务器回应的标头,然后空一行,再输出网页的源码。
curl -i https://www.google.com
-I (大写) 只打印服务器返回的 HTTP 标头。
-k
-k参数指定跳过 SSL 检测。不会检查服务器的 SSL 证书是否正确。
curl -k https://www.google.com
-L
-L参数会让 HTTP 请求跟随服务器的重定向。curl 默认不跟随重定向。
curl -L -d 'tweet=hi' https://api.twitter.com/tweet
–limit-rate
–limit-rate用来限制 HTTP 请求和回应的带宽,模拟慢网速的环境。
curl --limit-rate 200k https://google.com
将带宽限制在每秒 200K 字节。
-o
-o参数将服务器的回应保存成文件,等同于wget命令
curl -o example.html https://www.example.com
-O (大写)
-O参数将服务器回应保存成文件,并将 URL 的最后部分当作文件名。
curl -O https://www.example.com/foo/bar.html
命令将服务器回应保存成文件,文件名为bar.html。
-s
-s参数将不输出错误和进度信息。
curl -s https://www.example.com
命令一旦发生错误,不会显示错误信息。不发生错误的话,会正常显示运行结果。
-S
-S参数指定只输出错误信息,通常与-s一起使用。
curl -S https://google.com
没有任何输出,除非发生错误。
-x
-x参数指定 HTTP 请求的代理。
curl -x socks5://james:cats@myproxy.com:8080 https://www.example.com
指定 HTTP 请求通过myproxy.com:8080的 socks5 代理发出。
-X
-X参数指定 HTTP 请求的方法。
curl -X POST https://www.example.com
发出 POST 请求
-v
-v参数显示请求的详细过程。
curl -v https://www.example.com
显示详细过程