curl 模拟 GET 和 POST
GET请求
curl "https://example.com/"
发出简单的POST请求
要使用curl发出基本的POST请求,请在命令行上键入以下命令:
curl -X POST "https://example.com/"
该
-X
标志指定与HTTP服务器通信时要使用的自定义请求方法。默认情况下,除非指定了其他方法,否则将使用GET
方法。
通过POST请求发送其他字段
用户可以使用该-d
标志通过POST请求发送数据。以下POST请求发送username
, fullname
和password
字段以及它们的相应值。
curl -d "username=username&fullname=fullname&password=password2" -X POST "https://example.com/"
在POST请求中指定Content-Type
该-H
标志可用于发送特定的数据类型或带有curl的标头。以下命令发送带有请求的JSON对象。
curl -d '{json}' -H 'Content-Type: application/json' "https://example.com/login"
使用curl发送文件
我们还可以使用curl在命令行中发送完整文件。用于执行此操作的命令是:
curl --form "fileupload=@my-file.txt" "https://example.com/resource.cgi"
Curl 请求漏&参数
- 用“"号把请求体包起来:
"https://example.com/?username=username1&password=password"
- 使用转义:
curl -i https://example.com/?username=username1\&password=password