码迷,mamicode.com
首页 > Web开发 > 详细

Mock2 moco框架的http协议get方法Mock的实现

时间:2018-09-12 20:07:12      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:startup   uri   response   div   bubuko   png   chap   关键字   方法   

首先在Chapter7文件夹下再新建一个startGet.json

技术分享图片

startget.json代码如下,因为是get请求,所以要写method关键字,有两个,一个是有参数,一个是无参数的请求。

[
  {
    "description":"模拟一个没有参数的get请求",
    "request":{
      "uri":"/getDemo",
      "method":"get"
    },
    "response":{
      "text":"这是一个没有参数的get请求"
    }
  },

  {
    "description":"模拟一个带参数的get请求",
    "request":{
      "uri":"/getwithparam",
      "method":"get",
      "queries":{
        "name":"huhanshan",
        "age":"18"
      }
    },
    "response":{
      "text":"这是一个带参数的get请求,胡汉山又回来了"
    }
  }
]

启动mock服务器; java -jar ./moco-runner-0.12.0-standalone.jar http -p 8888 -c startupGet.json

技术分享图片

然后在浏览器访问:localhost:8888/getDemo      这是一个不带参数的请求

技术分享图片

log:

技术分享图片

然后也可以访问:http://localhost:8888/getwithparam?name=huhanshan&age=18   这是一个带参数的请求吧

技术分享图片

log:

技术分享图片

 

Mock2 moco框架的http协议get方法Mock的实现

标签:startup   uri   response   div   bubuko   png   chap   关键字   方法   

原文地址:https://www.cnblogs.com/peiminer/p/9636356.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!