Linux中以命令行的形式使用curl发送请求
-X 指定哪种HTTP请求方式
curl -X GET
curl -X POST
POST请求 两种方式
-F 创建POST请求 使用key=value
配对
curl -X POST -F 'name=Jason' -F 'email=jason@example.com' https://example.com/contact.php
使用该-F选项时,curl使用 Content-Type 为“multipart/form-data”发送数据。
-d 创建POST请求
默认使用application/x-www-form-urlencoded
这一Content-Type发送数据
curl -X POST -d 'name=Jason' -d 'email=jason@example.com' https://example.com/contact.php
若要指定特定的application/x-www-form-urlencoded
或Content-Type发送数据,使用-H
选项
curl -X POST -H "Content-Type: application/json" -d '{"name": "Jason", "email": "jason@example.com"}' https://example/contact
注意
命令行中&要转义,\&