前言:以下均为Windows使用,使用前不需要任何准备,打开命令提示符根据指令即可使用
关键字: curl
注意: 建议在请求前ping一下 ping http://www.123.com 或 ping 127.0.0.1(ip)
基本选项参数
curl参数:
-X 请求方法(GET、POST、PUT)
示例: curl -X GET http://www.123.com
-I (只显示响应头信息)
示例: curl -I http://www.123.com
-o 文件名 (将标准输出内容写入文件) 标准输出: 请求后打印在命令行中的结果示例: curl -o filename.txt http://www.123.com
-O 远程文件名(将标准输出内容写入远程文件中)示例: curl -O http://123.com/filename.html http://www.123.com
-L (跟随重定向)示例: curl -L http://123.com
请求头
-H 请求头(添加自定义请求头)示例: curl -H "Content-Type: application/json" http://123.com
-b cookie(发送cookie数据)示例: curl -b "session=123abd" http://123.com
-c 文件名(保存cookie到文件中)示例: curl -c filename http://123.com
请求体
-d 数据示例: curl -d "paramter1=123¶mter2=abc" http://123.com
-F 文件(模拟表单发送数据)示例: curl -F "file=@/user/abd.txt" http://123.com
--data-urlencode 数据(与d一致,不过会将数据先进行URL编码)示例: curl --data-urlencode "param1=value with spaces" http://example.com
-u 用户名 密码(服务器若需要用户和密码访问)示例: curl -u root:123123 http://123.com
-m 最大超时时间(设置最大传输时间)示例: curl -m 60 http://123.com