一、jar包下载:https://github.com/dreamhead/moco
二、准备mock的json文件
data.json内容:
####GET请求
[{"description": "response使用Content-Type为charset=GBK编码格式来查看返回信息为中文的内容","request": {"method": "get","uri": "/getlikheatenum","queries": {"channelid": "1024"}},"response": {"json": {"data": {"heat_degree": 4511,"like_num": 2685,"top_users": ["7981625233425640","4857325562408476","1004285809743988","1548065101238578","1265145454545454"]},"count": 0,"result": 1,"message": "操作成功","time": 1605936061,"headers":{"Content-Type":"text/html; charset=GBK"}}}},{"request": {"uri": {"match": "/test/\\w+"}},"response": {"text": "Hello, Moco"}}
]
三、启动命令:
前提是将json文件和jar包放在同一级目录,然后通过命令行的方式在当前目录运行
java -Dfile.encoding=utf-8 -jar moco-runner-1.4.0-standalone.jar http -p 9080 -c data.json
#解决中文编码问题
#1.-Dfile.encoding=utf-8 解决编码中文展示异常
#2.data.json文件response里也要添加
"headers":{"Content-Type":"text/html; charset=GBK"}
解决编码问题
四、请求
网页请求
http://127.0.0.1:9080/getlikheatenum?channelid=1024
postman请求:
五、日志
每请求一次都会有对应的日志打印
、
参考文章链接:
https://zhuanlan.zhihu.com/p/553354728 Mock工具之Moco使用教程
https://www.cnblogs.com/kay08/p/16251878.html moco请求在浏览器中文显示乱码