【问题标题】:Wiremock not able to match the urlWiremock 无法匹配 url
【发布时间】:2021-08-22 04:31:45
【问题描述】:

我有很基础的mapping.json

{
    "mappings": [
        {
            "priority": 1,
            "request": {
                "method": "GET",
                "url": "/your/url?and=query"
            },
            "response": {
                "status": 200,
                "statusMessage": "query param test"
            }
        },
        {
            "priority": 2,
            "request": {
                "method": "GET",
                "url": "/your"
            },
            "response": {
                "status": 200,
                "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

【问题讨论】:

  • 从邮递员那里打了完全相同的电话,它奏效了:|

标签: wiremock wiremock-standalone


【解决方案1】:

查看answer and comment from this question,,但要注意的是,如果您想在 CURL 请求中包含查询参数,则必须将 URL 放在引号中。

这就解释了为什么 Postman 可以工作,并且不带查询参数的 CURL 请求也可以工作,但带查询参数的 CURL 请求却不行。

curl -i 'http://localhost:8081/your/url?and=query' 应该足以解决您的问题(可能需要双引号而不是单引号?)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多