【问题标题】:URL Path Pattern matching in wiremockWiremock 中的 URL 路径模式匹配
【发布时间】:2017-02-13 11:22:10
【问题描述】:

wiremock 如何准确匹配带有编码 URL 的 URL 路径模式?我是否需要使用已编码的 URL 保存映射?这是我尝试了几个小时但无法正常工作的方法。

wiremock 中的映射

"request": {
    "urlPathPattern": "/Systems XYZ (ABC)/2016.10/aaa/bbb/api/ccc/customers/.*",
    "method": "GET",

我已经尝试过使用编码 URL 的不同变体,例如/Systems%20XYZ%20(ABC)/2016.10/aaa/bbb/api/ccc/customers/.* 甚至在映射中对 ( 和 ) 进行 URL 编码,但我的请求似乎不匹配

我尝试针对 wiremock 调用服务的 URI /Systems%20XYZ%20(ABC)/2016.10/aaa/bbb/api/ccc/customers/12345

/Systems XYZ (ABC)/2016.10/aaa/bbb/api/ccc/customers/.* 不过,我假设邮递员/浏览器会自动对空格进行编码。

这里有什么我遗漏的吗?尝试了很多组合,但似乎都不起作用。

【问题讨论】:

    标签: java wiremock


    【解决方案1】:

    当使用WireMock.Net时,你应该可以使用这个例子:

    {
      "Request": {
        "Path": {
          "Matchers": [
            {
              "Name": "RegexMatcher",
              "Pattern": "^/Systems XYZ (ABC)/2016.10/aaa/bbb/api/ccc/customers/.*$"
            }
          ]
        }
      },
      "Response": {
        "BodyAsJson": { "result": "test" },
        "Headers": {
          "Content-Type": "application/json"
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-08
      • 2022-08-11
      • 2021-08-22
      • 1970-01-01
      • 2014-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多