在线工具 在线编程 在线白板 在线工具 在线编程 在线白板

curl POST请求

大哥哪位知道,curl POST请求
最新回答
别闹~乖

2024-12-03 00:10:51

执行curl命令发送POST请求的基本语法如下:

curl -X POST catonmat.net

通过-c选项携带参数的请求示例:

curl -d 'login=emma&password=123' -X POST google.com/login

带参数请求的另一种写法:

curl -d 'login=emma' -d 'password=123' google.com/login

发送JSON格式请求:

curl -d '{"login": "emma", "pass": "123"}' -H 'Content-Type: application/json' google.com/login

发送XML格式请求:

curl -d 'ann123' -H 'Content-Type: text/xml' google.com/login

发送文本内容请求:

curl -d 'hello world' -H 'Content-Type: text/plain' google.com/login

上传文件内容请求:

curl -d '@data.txt' google.com/login

使用URL编码发送请求:

curl -d 'hello%20world' -H 'Content-Type: text/plain' google.com/login

上传二进制文件示例:

curl -F 'file=@photo.png' google.com/profile

发送二进制文件并指定MIME类型:

curl -F 'file=@photo.png;type=image/png' google.com/profile

若不自定义MIME类型,缺省将设置为application/octet-stream。

发送二进制文件时修改文件名:

curl -F 'file=@photo.png;filename=me.png' google.com/profile

查阅curl选项请访问:

catonmat.net/cookbooks/...