curl概述
curl 是一个命令行实用程序,允许用户创建网络请求
curl 在windows
、 linux
和 mac
上皆可使用
post请求
一个简单的 post 请求:
-x
:指定与远程服务器通信时将使用哪种 http 请求方法
curl -x post http://example.com
post 请求传递数据:
-d
:设置请求参数(拼接参数或json)
curl -x post http://example.com -d "firstname=john&lastname=andrew"
-h
:设置request里的header
curl -x post http://example.com -d '{"hello": "world"}' -h 'content-type: application/json'
-f
:模拟http表单数据提交 multipart post使用该-f选项时,curl使用的默认content-type是“multipart/form-data”
curl -x post http://example.com -f 'name=jason' -f 'email=jason@example.com'
get请求
带参数请求,参数用&连接
curl http://127.0.0.1:8080/login?admin&passwd=12345678
apifox工具获取
如下直接复制工具生成的即可,请求头和请求体都包含了
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论