curl请求在线生成

curl介绍

curl 是非常强大的命令行工具库,用于通过 URL 传输数据。它的名字就是客户端(client)的 URL 工具的意思(command line tool and library for transferring data with URLs)。 它的功能非常强大,命令行参数多达几十种。curl 是免费的开源软件,它支持包括 FTP、HTTP、HTTPS、FTP、SCP,SFTP 数十种协议。

参数说明

序号
参数
使用说明
参考样例
1
-A
-A参数指定客户端的用户代理标头,即User-Agent。curl 的默认用户代理字符串是curl/[version]。
curl -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36' https://google.com
2
-b
-b参数用来向服务器发送 Cookie。
curl -b 'foo1=bar' -b 'foo2=baz' https://google.com
3
-c
-c参数将服务器设置的 Cookie 写入一个文件
curl -c cookies.txt https://www.google.com
4
-d
-d参数用于发送 POST 请求的数据体
curl -d'login=emma&password=123'-X POST https://google.com/login
5
--data-urlencode
--data-urlencode参数等同于-d,发送 POST 请求的数据体,区别在于会自动将发送的数据进行 URL 编码。
curl --data-urlencode 'comment=hello world' https://google.com/login
6
-e
e参数用来设置 HTTP 的标头Referer,表示请求的来源
curl -e 'https://google.com?q=example' https://www.example.com
7
-F
-F参数用来向服务器上传二进制文件。类型及文件名,可不做指定
curl -F 'file=@photo.png;type=image/png;filename=me.png' https://google.com/profile
8
-G
-G参数用来构造 URL 的查询字符串。实际请求的 URL 为https://google.com/search?q=kitties&count=20。如果省略--G,会发出一个 POST 请求
curl -G -d 'q=kitties' -d 'count=20' https://google.com/search
9
-H
-H参数添加 HTTP 请求的标头。
curl -H 'Accept-Language: en-US' https://google.com
10
-i
-i参数打印出服务器回应的 HTTP 标头。-I参数向服务器发出 HEAD 请求,然会将服务器返回的 HTTP 标头打印出来。--head参数等同于-I
curl -i https://www.example.com
11
-k
-k参数指定跳过 SSL 检测。
curl -k https://www.example.com
12
-L
-L参数会让 HTTP 请求跟随服务器的重定向。curl 默认不跟随重定向。
curl -L -d 'tweet=hi' https://api.twitter.com/tweet
13
--limit-rate
--limit-rate用来限制 HTTP 请求和回应的带宽,模拟慢网速的环境。将带宽限制在每秒 200K 字节。
curl --limit-rate 200k https://google.com
14
-s
-s参数将不输出错误和进度信息。-S参数指定只输出错误信息,通常与-o一起使用。
curl -s https://www.example.com curl -s -o /dev/null https://google.com
15
-u
-u参数用来设置服务器认证的用户名和密码。
curl -u 'zhangsan:123456' https://google.com/login 或者 curl https://zhangsan:12345@google.com/login
16
-v
-v参数输出通信的整个过程,用于调试。
curl -v https://www.example.com
17
--trace
--trace参数也可以用于调试,还会输出原始的二进制数据。
curl --trace - https://www.example.com
18
-x
-x参数指定 HTTP 请求的代理,通过myproxy.com:8080的 socks5 代理发出。-X参数指定 HTTP 请求的方法。
curl -x socks5://james:cats@myproxy.com:8080 https://www.example.com curl -X POST https://www.example.com