1.启动 moco的jar包
java -jar ./moco-runner-0.11.0-standalone.jar http -p 8888 -c startupPostAndGet.json
2.注意事项
浏览器页面显示乱码 解决办法:在response中添加设置编码格式为“GBK”, "headers":{"Content-Type":"text/html;charset=gbk"} get方法中入参使用queries,post请求中入参使用forms
3.json功能演示,可配合jmeter工具演示效果
包含如下功能:
3.1 post请求,带参,不带参,带cookies,带header
3.2 get请求,带参,不带参,带cookies
3.3 重定向到百度,重定向到自定义内部网页
[{
"description": "这是一个post请求",
"request": {
"uri": "/postdemo",
"method": "post"
},
"response": {
"text": "这是一个post请求",
"headers": {
"Content-Type": "text/html;charset=gbk"
}
}
},
{
"description": "这是一个带参数的post请求",
"request": {
"uri": "/postwithpara",
"method": "post",
"forms": {
"name": "huhansan",
"sex": "man"
}
},
"response": {
"text": "我胡汉三带着参数来了",
"headers": {
"Content-Type": "text/html;charset=gbk"
}
}
}, {
"description": "模拟一个没有参数的get请求",
"request": {
"uri": "/getdemo",
"method": "get"
},
"response": {
"text": "这是一个没有入参的get请求",
"headers": {
"Content-Type": "text/html;charset=gbk"
}
}
}, {
"description": "模拟一个带参数的get请求",
"request": {
"uri": "/getwithparam",
"method": "get",
"queries": {
"name": "huhansan",
"age": "18"
}
},
"response": {
"text": "我胡汉三又回来了",
"headers": {
"Content-Type": "text/html;charset=gbk"
}
}
}, {
"description": "get请求模拟一个带cookies的请求",
"request": {
"uri": "/get/with/cookies",
"method": "get",
"cookies": {
"login": "true"
}
},
"response": {
"text": "这是一个需要携带cookies信息才能返回的get请求",
"headers": {
"Content-Type": "text/html;charset=gbk"
}
}
},
{
"description": "post请求模拟一个带cookies的请求",
"request": {
"uri": "/post/with/cookies",
"method": "post",
"cookies": {
"login": "true"
},
"json": {
"name": "huhansan",
"age": "18"
}
},
"response": {
"status": 200,
"json": {
"huhansan": "success",
"status": "1"
},
"headers": {
"Content-Type": "text/html;charset=gbk"
}
}
},
{
"description": "这是一个带header的post请求",
"request": {
"uri": "/post/with/headers",
"method": "post",
"headers": {
"content-type": "application/json"
},
"json": {
"name": "wanglaowu",
"sex": "woman"
}
},
"response": {
"status": 200,
"json": {
"huhansan": "success",
"status": "1"
},
"headers": {
"Content-Type": "text/html;charset=gbk"
}
}
},
{
"description": "这是重定向到百度",
"request": {
"uri": "/redirect"
},
"redirectTo": "http://www.baidu.com"
},
{
"description": "这是重定向到自己的网页",
"request": {
"uri": "/redirect/topath"
},
"redirectTo": "/redirect/new"
},
{
"description": "这是被重定向请求",
"request": {
"uri": "/redirect/new"
},
"response": {
"text": "重定向成功了",
"headers": {
"Content-Type": "text/html;charset=gbk"
}
}
}
]