Moco模擬服務器post&get請求 (二)


1、moco啟動命令如下:
java -jar moco-runner-0.12.0-standalone.jar 協議類型 -p 端口號 -c json配置文件

2、帶參數的get請求

[
{
"request":{
"method":"get",
"uri":"/api/get_event_list",
"queries":{
"eid":"1"
}
},
"response":
{
"file":"get_data.json"
}
}
]
其中 get_data.json文件如下(我用了數據分離):
{
"status":"200",
"msg":"success",
"data": {
"eid": "1",
"name": "Moco發布會",
"limit": "2000",
"status": "true",
"address": "北京",
"start_time": "2019-6-18 10:00:00"
}
}

3、啟動get.json文件 -- > java -jar moco-runner-0.12.0-standalone.jar http -p 8899 -c get.json

4、在瀏覽器輸入http://localhost:8899/api/get_event_list?eid=1 會response響應get請求

5、不帶get參數如下:

 

6、帶參數的 post 請求 --- &帶 heades 實例

a、用form -data

[
{
"request": {
"method":"post",
"uri":"/api/add_event",
"headers": {
"content-type": "application/x-www-form-urlencoded"
},
"forms":{
"eid":"1"
}
},
"response":{
"file":"post_data.json"
}
}
]
--->在postman中添加


b、---- 其中也可以用 json --
[
{
"request": {
"method":"post",
"uri":"/api/add_event",
"headers": {
"content-type": "application/json"
},
"json":{
"eid":"1"
}
},
"response":{
"file":"post_data.json"
}
}
]

其中 post_data.json 數據如下:
{
"status":"10021",
"msg":"parament error"
}
7、啟動post.json文件 --> java -jar moco-runner-0.12.0-standalone.jar http -p 8899 -c post.json
出現下圖,表示post.json 是沒有問題的。

8、不帶post請求的實例如下:

 

9、post 、get 等請求方法 需要借助 postman 接口測試工具來測試 response 數據是否響應回復。

postman是開源的接口測試工具,下載鏈接:https://www.getpostman.com/downloads/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM