一 简介
moco是一个服务器,能 处理http、https、socket请求,可以用来调测前端或后端请求接口时使用,详情查看:https://github.com/dreamhead/moco/tree/master/moco-doc
二 下载
在github上下载moco的jar,地址:https://github.com/dreamhead/moco
三 http服务
1 在moco的jar的同级目录下,新建一个foo.json,内容如下:
{
"request" :
{
"uri" : "/foo"
},
"response" :
{
"text" : "bar"
}
}
2 启动服务(前提:已经安装了jdk)
http:一个http服务;-p:端口号;-c:处理的文件;
java -jar moco-runner-<version>-standalone.jar http -p 12306 -c foo.json
3 访问
在浏览器上,访问http://localhost:12306/foo,将返回bar字符
四 socket服务
1 在moco的jar的同级目录下,新建一个foo.json,内容如下:
{
"request" :
{
"text" : "foo"
},
"response" :
{
"text" : "bar"
}
}
2 启动服务(前提:已经安装了jdk)
socket:一个socket服务;-p:端口号;-c:处理的文件;
java -jar moco-runner-<version>-standalone.jar socket -p 12306 -c foo.json
3 访问
当使用socket工具访问本地ip的12306端口,并发送foo信息时,返回bar字符