2

使用curl命令模拟POST和GET请求

 2 years ago
source link: https://wakzz.cn/2018/12/22/linux/%E4%BD%BF%E7%94%A8curl%E5%91%BD%E4%BB%A4%E6%A8%A1%E6%8B%9FPOST%E5%92%8CGET%E8%AF%B7%E6%B1%82/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

使用curl命令模拟POST和GET请求

祈雨的博客
2018-12-22

转载自CSDN本文链接地址: 使用curl 命令模拟POST/GET请求

curl命令是一个利用URL规则在命令行下工作的文件传输工具。它支持文件的上传和下载。curl支持包括HTTP、HTTPS、ftp等众多协议,还支持POST、cookies、认证、从指定偏移处下载部分文件、用户代理字符串、限速、文件大小、进度条等特征。

在进行web后台程序开发测试过程中,常常会需要发送url进行测试,使用curl可以方便地模拟出符合需求的url命令

假设目标url为: 127.0.0.1:8080/login

使用curl发送GET请求:

curl protocol://address:port/url?args
curl http://127.0.0.1:8080/login?admin&passwd=12345678

使用curl发送POST请求:

curl -d "args" protocol://address:port/url
curl -d "user=admin&passwd=12345678" http://127.0.0.1:8080/login

这种方法是参数直接在header里面的,如需将输出指定到文件可以通过重定向进行操作。

curl -H "Content-Type:application/json" -X POST -d 'json data' URL
curl -H "Content-Type:application/json" -X POST -d '{"user":"admin", "passwd":"12345678"}' http://127.0.0.1:8000/login

关于curl的更多信息可以查看这里


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK