Wiremock与编码的url不匹配



我无法使wiremock与编码的URL的匹配

String encodedURL="/a?b%3D5";
String url = URLDecoder.decode(encodedURL, StandardCharsets.UTF_8.toString());
System.out.println("Decoded = " + url);
WireMock.stubFor(WireMock.get(WireMock.urlEqualTo(encodedURL))
.willReturn(jsonResponse(200, "abc")));
// Info such as port numbers is also available
int port = wmRuntimeInfo.getHttpPort();
RestTemplate r = new RestTemplate();

String result  = r.getForObject("http://localhost:" +port+encodedURL,String.class);
System.out.println("Result = " + result);

和无线模拟报告

最近的存根=/a?b%3D5请求=/a?b%253D5

如果我使用解码的url进行调用,wiremock会报告

最近的存根=/a?b=5请求=/a?b%253D5

我使用的是wiremock 2.32.0,junit 5,spring boot 2.6.3我做错了什么?

将编码的路径和查询(encodedUrl(传递给RestTemplate的GET请求。但是,RestTemplate会为您编码url。这意味着已经编码的路径和查询被再次编码。尝试使用:r.getForObject("http://localhost:" +port+url,String.class)

最新更新