curl是一个可以在命令行下来发起http请求的,简单来说,就是命令行下模拟浏览器发起Http请求
我们看一下常用的curl例子:
获取网页内容:
1 |
curl https://503error.com |
强制解析域名:
1 |
curl --resolve www.example.org:80:127.0.0.1 <a href="http://www.example.org/">http://www.example.org/</a> |
访问指定端口:
1 |
curl <a href="http://www.example.org:1234/">http://www.example.org:1234/</a> |
使用代理访问某网站:
1 |
curl --proxy <a href="http://proxy.example.org:4321/">http://proxy.example.org:4321</a> <a href="http://remote.example.org/">http://remote.example.org/</a> |
使用用户名密码登录:
1 |
curl -u user:password <a href="http://example.org/">http://example.org/</a> |
提交一个form(GET)
1 2 3 4 |
<form method="GET" action="junk.cgi"> <input type=text name="birthyear"> <input type=submit name=press value="OK"> </form> |
1 |
curl "<a href="http://www.hotmail.com/when/junk.cgi?birthyear=1905&press=OK">http://www.hotmail.com/when/junk.cgi?birthyear=1905&press=OK</a>" |
提交一个form(POST)
1 2 3 4 |
<form method="POST" action="junk.cgi"> <input type=text name="birthyear"> <input type=submit name=press value=" OK "> </form> |
1 |
curl --data "birthyear=1905&press=%20OK%20" <a href="http://www.example.com/when.cgi">http://www.example.com/when.cgi</a> |
encode:
1 |
curl --data-urlencode "name=I am Daniel" <a href="http://www.example.com/">http://www.example.com</a> |
Referer:
1 |
curl --referer <a href="http://www.example.come/">http://www.example.come</a> <a href="http://www.example.com/">http://www.example.com</a> |
User Agent:
1 |
curl --user-agent "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" |
Cookie options:
1 |
curl --cookie "name=Daniel" <a href="http://www.example.com/">http://www.example.com</a> |
参考地址:https://curl.haxx.se/docs/httpscripting.html
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021