我正在尝试使用 wiremock JSON stub 文件模拟查询参数。
当我这样做时它会起作用:
{
"request": {
"method": "GET",
"url": "/posts?id=1",
},
//...
}
但是,当我更改查询参数以使用这样的专用字段时,它不再起作用:
{
"request": {
"method": "GET",
"urlPath": "/posts",
"queryParameters": {
"id": {
"equalTo": "1"
}
}
},
//...
}
知道为什么吗?
测试请求看起来像 http://some-host/posts?id=1
最佳答案
这对我有用,将您的 "urlPath"
更改为 "urlPathPattern"
但在构建此 JSON
时要小心。所以 urlPath
是精确匹配模式,但 urlPathPattern
是路径和查询参数上的正则表达式匹配
{
"request": {
"urlPathPattern": "/posts",
"method": "GET",
"queryParameters": {
"id": {
"equalTo": "1"
}
}
},
"response": {
"status": 200,
"body":"This is successful"
}
}
关于java - Wiremock 查询参数 JSON stub 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50523008/