0

我正在尝试使用 WireMock 创建动态模拟。我的网址是这样的:

http://localhost:8080/manage/classids/query1=ns1/query2=id1

然后我想输出为

{ 
   "yourId":"id1"
}

我试着这样做

{
    "name": "Req_GET",
    "request": {
        "urlPathPattern": "/manage/classids/query1=([a-zA-Z0-9]*)/query2=([a-zA-Z0-9]*)",
        "method": "GET"
    },
    "response": {
        "status": 200,
        "jsonBody": {
            "yourId": "{{request.path.[3]}}"
        },
        "transformers": [
            "response-template"
        ],
        "headers": {
            "Content-Type": "application/json"
        }
    }
}

但我无法在“=”之后拆分响应,它在“/”之后是完整的

{ 
   "yourId":"query2=id1"
}
4

1 回答 1

0

您可以使用 WireMock 的请求模型直接引用查询参数

...
"yourId": "{{request.query.query1}}"
...
于 2021-11-23T14:16:51.227 回答