moco模拟接口具体操作

1.get请求

[
{
"description": "模拟一个没有参数的get请求",
"request": {
"uri": "/getdemo",
"method": "get"
},
"response": {
"text": "这是一个没有参数的get请求"
}
},
{
"description": "模拟一个带参数的get请求",
"request": {
"uri": "/getwithparam",
"method": "get",
"queries": {
"name": "hu",
"age": "18"
}
},
"response": {
"text": "我回来了"
}
}

]

2.post请求
[
{
"description": "模拟一个post请求",
"request": {
"uri": "/postdemo",
"method": "post"
},
"response": {
"text": "这是我的第一个mock的post请求"
}
},{
"description": "post带参",
"request": {
"uri":"/postwithparam",
"method": "post",
"forms": {
"name": "huhansan",
"sex": "man"
}
},
"response": {
"text": "我回来了"
}
}
]
3.带header的post请求
[
{
"description": "带header的信息的post请求",
"request": {
"uri": "/post/headers",
"method": "post",
"headers": {
"content-type": "application/json"
},
"json": {
"name": "hu",
"age": "18"
}
},
"response": {
"json": {
"info": "success",
"status": "1"
}
}
}
]
4.重定向
[
{
"description": "重定向到百度",
"request": {
"uri": "/redirect"
},
"redirectTo": "http://www.baidu.com"
},{
"description": "重定向到一个自己的网页",
"request": {
"uri": "/redirect/topath"
},
"redirectTo": "/redirect/new"
},
{
"description": "这是被重定向的请求",
"request": {
"uri": "/redirect/new"
},
"response": {
"text": "重定向成功"
}
}
]
5.带cookie的请求
[
{
"description": "这是一个会返回cookies信息的get请求",
"request": {
"uri": "/getCookies",
"method": "get"
},
"response": {
"cookies": {
"login": "true"
},
"text": "恭喜你获得cookies信息成功"
}

},
{
"description": "需要带cookies的get请求",
"request": {
"uri": "/get/with/cookies",
"method": "get",
"cookies":{
"login": "true"
}
},
"response": {
"text": "需要带cookies才能访问的get请求"
}
},{
"description": "需要带cookies的post请求",
"request": {
"uri": "/post/with/cookies",
"method": "post",
"cookies":{
"login": "true"
},
"json": {
"name": "hu",
"age": "18"
}
},
"response": {
"status": 200,
"json": {
"gg": "success",
"status": "1"
}
}
}
]


posted @ 2021-08-16 14:40  韩伊  阅读(282)  评论(0)    收藏  举报