MENU

curl 模拟 GET 和 POST

November 26, 2020 • Read: 1287 • 默认分类

curl 模拟 GET 和 POST

GET请求

curl "https://example.com/"

image-20201126201318561

发出简单的POST请求

要使用curl发出基本的POST请求,请在命令行上键入以下命令:

curl -X POST "https://example.com/"

-X标志指定与HTTP服务器通信时要使用的自定义请求方法。默认情况下,除非指定了其他方法,否则将使用GET方法。

通过POST请求发送其他字段

用户可以使用该-d标志通过POST请求发送数据。以下POST请求发送username, fullnamepassword字段以及它们的相应值。

curl -d "username=username&fullname=fullname&password=password2" -X POST "https://example.com/"

image-20201126201431158

在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 请求漏&参数

  1. 用“"号把请求体包起来:"https://example.com/?username=username1&password=password"
  2. 使用转义:curl -i https://example.com/?username=username1\&password=password
Archives QR Code Tip
QR Code for this page
Tipping QR Code