在 linux 中 curl 是一款利用 URL 规则在命令下工作的开源文件传输工具.

以下 demo 中,使用文件 index.php 作为实例演示, index.php 中内容为

1
2
3
4
5
6
7
//访问本页面的地址为 www.test.com
<?php
print_r($_GET);

echo "分隔符";

print_r($_POST);

test

没有参数, 获取页面内容

1
curl  www.test.com

curl

参数 I 显示 HTTP 头

1
2
3
curl -I www.test.com   [显示头信息,不显示内容]

curl -i www.test.com [显示头和内容]

curl I

curl i

链接保存到文件中

1
curl www.test.com > index.html

curl url

使用 -d -X发送 POST 请求

1
2
curl -d "post1=001&post2=002" www.test.com
curl -d "post1=001&post2=002" -X POST www.test.com # X大写 POST 大写

curl post

curl post

使用 -d -G 发送 GET 请求

1
curl -d "get01=111&get02=002" -G GET www.test.com

curl get