Moco模拟服务器post&get请求 (二)

一、moco启动命令以下:
java -jar moco-runner-0.12.0-standalone.jar 协议类型 -p 端口号 -c json配置文件java

二、带参数的get请求json

[
{
"request":{
"method":"get",
"uri":"/api/get_event_list",
"queries":{
"eid":"1"
}
},
"response":
{
"file":"get_data.json"
}
}
]
其中 get_data.json文件以下(我用了数据分离):
{
"status":"200",
"msg":"success",
"data": {
"eid": "1",
"name": "Moco发布会",
"limit": "2000",
"status": "true",
"address": "北京",
"start_time": "2019-6-18 10:00:00"
}
}

三、启动get.json文件 -- > java -jar moco-runner-0.12.0-standalone.jar http -p 8899 -c get.json

四、在浏览器输入http://localhost:8899/api/get_event_list?eid=1 会response响应get请求api

五、不带get参数以下:浏览器

 

六、带参数的 post 请求 --- &带 heades 实例app

a、用form -data工具

[
{
"request": {
"method":"post",
"uri":"/api/add_event",
"headers": {
"content-type": "application/x-www-form-urlencoded"
},
"forms":{
"eid":"1"
}
},
"response":{
"file":"post_data.json"
}
}
]
--->在postman中添加


b、---- 其中也能够用 json --
[
{
"request": {
"method":"post",
"uri":"/api/add_event",
"headers": {
"content-type": "application/json"
},
"json":{
"eid":"1"
}
},
"response":{
"file":"post_data.json"
}
}
]

其中 post_data.json 数据以下:
{
"status":"10021",
"msg":"parament error"
}
七、启动post.json文件 --> java -jar moco-runner-0.12.0-standalone.jar http -p 8899 -c post.json
出现下图,表示post.json 是没有问题的。

八、不带post请求的实例以下:post

 

九、post 、get 等请求方法 须要借助 postman 接口测试工具来测试 response 数据是否响应回复。测试

postman是开源的接口测试工具,下载连接:https://www.getpostman.com/downloads/url

相关文章
相关标签/搜索