问题描述
我有非常基本的mapping.json
{
"mappings": [
{
"priority": 1,"request": {
"method": "GET","url": "/your/url?and=query"
},"response": {
"status": 200,"statusMessage": "query param test"
}
},{
"priority": 2,"url": "/your"
},"statusMessage": "no query param"
}
}
]
}
这与 documentation 中给出的示例完全相同。
结果:
admin ~ % curl -i http://localhost:8081/your
HTTP/1.1 200 no query param
Matched-Stub-Id: 6ff84303-8abb-48d0-bd27-679de118afc7
transfer-encoding: chunked
Server: Jetty(9.2.z-SNAPSHOT)
admin ~ % curl -i http://localhost:8081/your/url?and=query
zsh: no matches found: http://localhost:8081/your/url?and=query
admin ~ %
无法弄清楚我在这里做错了什么。这与文档中给出的示例完全相同。我尝试像这样放置查询参数:
"queryParameters" : {
"search_term" : {
"equalTo" : "wiremock"
}
},
这也没有帮助。 TIA
解决方法
查看 answer and comment from this question,,但 tl;dr 是,如果您想在 CURL 请求中包含查询参数,则必须将 URL 放在引号中。
这就解释了为什么 Postman 起作用了,没有查询参数的 CURL 请求也起作用了,但是带有查询参数的 CURL 请求没有。
curl -i 'http://localhost:8081/your/url?and=query'
应该足以解决您的问题(可能需要双引号而不是单引号?)