带参数的get方法实现

单个接口,不带参数的get请求

新建json文件命令为startupGet,添加内容,代码如下

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

在Terminal里输入cd Chapter7回车
输入java -jar -Dfile.encoding=UTF-8 ./moco-runner-0.11.0-standalone.jar http -p 8890 -c startupGet.json回车
在浏览器打开http://127.0.0.1:8890/getdemo
在这里插入图片描述

多个接口,带参数的get请求

在startupGet文件添加内容,代码如下

[
  {
    "description":"模拟一个没有参数的get请求",
    "request":{
      "uri":"/getdemo",
      "method":"get"
    },
    "response": {
      "text": "这是一个没有参数的get请求"
    }
    },
  {
    "description":"模拟一个带参数的get请求",
    "request":{
      "uri":"/getwithparam",
      "method":"get",
      "queries":{
        "name":"huhansan",
        "age":"18"
      }
    },
    "response":{
      "text":"我胡汉三又回来啦!!!"
    }
  }


]

在浏览器打开http://127.0.0.1:8890/getwithparam?name=huhansan&age=18
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42884654/article/details/83018024