当前位置:网站首页>Mock service Moco series (II) - JSON format, file file, header, cookie, solving Chinese garbled code
Mock service Moco series (II) - JSON format, file file, header, cookie, solving Chinese garbled code
2022-07-25 17:50:00 【wangmcn】
Mock service moco series ( Two )
Json Format 、File file 、Header、Cookie、 Solve the Chinese garbled code
Catalog
- 1、Json Format
- 2、File file
- 3、Header
- 4、Cookie
- 5、 Solve the Chinese garbled code
1、Json Format
1、 establish 04Json.json The configuration file .
json by Json Format .
The contents are as follows :
[
{
"description":"Json Format ",
"request":{
"uri":"/json",
"method":"get"
},
"response":{
"json":{
"username":"admin",
"password":"123456"
}
}
}
]2、 Input start moco The service command .
java -jar moco-runner-0.12.0-standalone.jar http -p 8083 -c 04Json.json
3、Postman visit moco Service address .
Open the installed Postman.
The agreement type is selected as GET
Access address :http://localhost:8083/json
Click on Send, The access results show : With Json Format output .
2、File file
1、 establish 05File.json、data.json、data2.json The configuration file .
Request part file Read data.json File as request parameter .
Response part file Read data2.json File as response content .
05File.json The contents are as follows :
[
{
"description":"File file ",
"request":{
"uri":"/file",
"method":"post",
"file":{
"json":"data.json"
}
},
"response":{
"file":"data2.json"
}
}
]data.json The contents are as follows :
{
"username":"admin",
"password":"123456"
}data2.json The contents are as follows :
{
"username":"administrator",
"password":"abcdef"
}2、 Input start moco The service command .
java -jar moco-runner-0.12.0-standalone.jar http -p 8083 -c 05File.json
3、Postman visit moco Service address .
Open the installed Postman.
The agreement type is selected as POST
Access address :http://localhost:8083/file
Body add to data.json As a request parameter .
Click on Send, The access results show :data2.json The content of the file is the response content .
3、Header
1、 establish 06Header.json The configuration file .
headers: Message header .
Request part headers add to content-type The content type is Json Format , send out Json Format data .
Response part headers Add custom parameters Self-Header Its corresponding value , The response content is Json Format .
The contents are as follows :
[
{
"description":"Header",
"request":{
"uri":"/header",
"method":"post",
"headers":{
"content-type":"application/json"
},
"json":{
"username":"admin",
"password":"123456"
}
},
"response":{
"headers":{
"Self-Header":"MySelfHeader"
},
"json":{
"username":"administrator",
"password":"abcdef"
}
}
}
]2、 Input start moco The service command .
java -jar moco-runner-0.12.0-standalone.jar http -p 8083 -c 06Header.json
3、Postman visit moco Service address .
Open the installed Postman.
The agreement type is selected as POST
Access address :http://localhost:8083/header
Headers Add key Content-Type, value application/json.
Body Add requested Json data .
Click on Send, The access results show :
Body Content is displayed in Json Format output .
Headers Display custom parameters Self-Header Information of its corresponding value .
4、Cookie
1、 establish 07Cookie.json The configuration file .
The configuration file has 2 Interface ( Yes Cookie Of Get request 、 Yes Cookie Of Post request ).
cookies:cookie Information .
status: Response status code .
The contents are as follows :
[
{
"description":"Cookie(Get request )",
"request":{
"uri":"/get/cookie",
"method":"get",
"cookies":{
"login":"true"
}
},
"response":{
"text":"Moco Cookie"
}
},
{
"description":"Cookie(Post request )",
"request":{
"uri":"/post/cookie",
"method":"post",
"cookies":{
"login":"true"
},
"json":{
"username":"admin",
"password":"123456"
}
},
"response":{
"status":200,
"json":{
"admin":"success",
"status":"1"
}
}
}
]2、 Input start moco The service command .
java -jar moco-runner-0.12.0-standalone.jar http -p 8083 -c 07Cookie.json
3、Postman visit moco Service address .
Open the installed Postman.
(1)Cookie(Get request )
The agreement type is selected as GET
Access address :http://localhost:8083/get/cookie
Headers Add key Cookie, value login=true.
Click on Send, The access results show : With Text Format output .
(2)Cookie(Post request )
The agreement type is selected as POST
Access address :http://localhost:8083/post/cookie
Headers Add key Cookie, value login=true.
Headers Add key Content-Type, value application/json.
Body Add requested Json data .
Click on Send, The access results show :
Body Content is displayed in Json Format output .
Status code is 200.
5、 Solve the Chinese garbled code
One 、 problem :
When the response content is in Chinese ( Such as : Response content returned ), The browser displays garbled code when viewing , As shown in the figure :
Two 、 solve :
In profile response Add and set the encoding format to “GBK” that will do .
"headers":{"Content-Type":"text/html;charset=gbk"}
1、 establish 08CharsetGBK.json The configuration file .
The contents are as follows :
[
{
"description":" Solve the Chinese garbled code ",
"request":{
"uri":"/demo",
"method":"get"
},
"response":{
"headers":{
"Content-Type":"text/html;charset=gbk"
},
"text":" Response content returned "
}
}
]2、 Input start moco The service command .
java -jar moco-runner-0.12.0-standalone.jar http -p 8083 -c 08CharsetGBK.json
3、 Browser access moco Service address .
Access address :http://localhost:8083/demo
The access results show : Chinese display is normal .
边栏推荐
- Which futures account is the best and safest
- Which one of the electronic products has a longer service life??
- Unity 贝塞尔曲线的创建
- 【无标题】
- Mock服务moco系列(三)- 重定向、正则表达式、延迟、模板、事件、分模块设计
- I2C通信——时序图
- 栈的顺序存储结构,链式存储结构及实现
- [vscode] support argparser/ accept command line parameters
- MySQL数据库常用命令
- We were tossed all night by a Kong performance bug
猜你喜欢

自动化测试 PO设计模型

Thesis reading_ Multi task learning_ MMoE

I2C通信——时序图

【硬件工程师】元器件选型都不会?

I'm also drunk. Eureka delayed registration and this pit!

How to fix the first row title when scrolling down in Excel table / WPS table?

stm32F407------SPI

PageHelper can also be combined with lambda expressions to achieve concise paging encapsulation

Redis source code and design analysis -- 15. RDB persistence mechanism

11、照相机与透镜
随机推荐
WPF implements user avatar selector
P2P 之 UDP穿透NAT的原理与实现
go defer与recover简单笔记
吴恩达机器学习编程作业无法暂停pause问题解决
Mock服务moco系列(三)- 重定向、正则表达式、延迟、模板、事件、分模块设计
Is it safe to open a futures account online? How to apply for a low handling fee?
With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
食品安全 | 八问八答带你重新认识小龙虾!这样吃才对!
Redis源码与设计剖析 -- 16.AOF持久化机制
go语言context控制函数执行超时返回
Notes on Flickr's dataset
实时黄金交易平台哪个可靠安全?
NPDP多少分通过?如何高分通过?
I want to manage money. I don't understand. Is there a principal guaranteed financial product?
PageHelper can also be combined with lambda expressions to achieve concise paging encapsulation
Lwip之内存与包缓冲管理
Redis源码与设计剖析 -- 18.Redis网络连接库分析
对灰度图像的三维函数显示
Redis source code and design analysis -- 17. Redis event processing
交友活动记录