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

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

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

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

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

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

log:

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

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

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

log:

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

 

相关文章:

  • 2021-12-09
  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2021-12-11
猜你喜欢
  • 2021-09-06
  • 2021-10-08
  • 2021-10-19
  • 2021-12-12
  • 2021-08-24
  • 2021-10-23
  • 2021-05-24
相关资源
相似解决方案