gpt4 book ai didi

java - 使用wiremock拦截POST请求以检查其查询参数

转载 作者:行者123 更新时间:2023-11-30 05:24:47 30 4
gpt4 key购买 nike

是否可以使用 Wiremock 对已知的 POST 请求进行测试,以检查请求具有的查询参数?

wireMockServer.start();
stubFor(post(urlMatching("http://localhost:8080/smth.*"))
.withHeader("Content-Type", equalTo("application/x-www-form-urlencoded"))
.withQueryParam("authorizationcode", equalTo("123456"))
.withQueryParam("baseamount", equalTo("0.10"))
.withQueryParam("basecurrency", equalTo("978"))
.withQueryParam("cardcountry", equalTo("ITA"))
.withQueryParam("cardexpirydate", equalTo("0120"))
.withQueryParam("customfield",equalTo("some+custom+field"))
.withQueryParam("result", equalTo("APPROVED"))
.willReturn(aResponse().withBody(RESPONSE))
);
wireMockServer.stop();

我不知道我是否走在正确的道路上,我在文档中找不到好的示例。

最佳答案

您添加的所有参数和 header 都必须出现在请求中,以便 WireMock 匹配。这应该正确测试请求中查询参数的存在。如果您在将请求与 stub 匹配时遇到问题,可以在注册 stub 后使用断点停止代码执行并计算(IntelliJ 中的 ALT + F8)此表达式:

    WireMock.listAllStubMappings()

我在 WireMock 作者的 GitHub 中找到了一些包含完整配置示例的存储库: https://github.com/tomakehurst/wiremock-demohttps://github.com/tomakehurst/wiremock-presentation-examples

我不确定这是否完全回答了您的问题。如果您有任何具体问题,请提供导致该问题的代码: https://stackoverflow.com/help/minimal-reproducible-example

关于java - 使用wiremock拦截POST请求以检查其查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58876833/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com