curl 是常用的命令行工具,用来请求 Web 服务器。它的名字就是客户端(client)的 URL 工具的意思。
它的功能非常强大,命令行参数多达几十种。如果熟练的话,完全可以取代 Postman 这一类的图形界面工具。
注意:安装的时候可能会遇到报错,有可能是openssl没装
apt install curl
apt install openssl
apt install openssl-dev
一些常用参数的用法
参数 | 说明 | 示例 |
---|---|---|
-A | 设置user-agent | curl -A “chrome” https://www.baidu.com |
-X | 用指定方法请求 | curl -X POST http://httpbin.org/post |
-I | 只返回请求的头信息 | curl -I http://www.baidu.com |
-d | 以POST方法请求url,并发送相应的参数 | curl -d “a=1&b=2&c=2” http://httpbin.org/post 或 curl -d a=1 -d b=2 http://httpbin.org/post |
-O | 下载文件并以远程的文件名保存 | curl -O http://httpbin.org/image/jpeg |
-o | 下载文件并以指定的文件名保存 | curl -o fox.jpeg http://httpbin.org/image/jpeg |
-L | 跟随重定向请求 | curl -IL https://baidu.com |
-H | 设置头信息 | curl -o image.webp -H “accept:image/webp” http://httpbin.org/image |
-k | 允许发起不安全的SSL请求 | curl -k https://www.12306.cn |
-b | 设置cookies | curl -b a=test http://httpbin.org/cookies |