Wiremock 无法匹配请求
Wiremock failed to match request
我正在尝试断言在 OAuth2 流程中调用的先前存根端点:
stubFor(
post(urlPathEqualTo("/token"))
.withHeader(AUTHORIZATION, equalTo("Basic cGluLmFwaS5jbGllbnRJZDpwaW4uYXBpLmNsaWVudFNlY3JldA=="))
.withHeader(CONTENT_TYPE, equalTo("application/x-www-form-urlencoded;charset=UTF-8"))
.withHeader(ACCEPT, equalTo(APPLICATION_JSON_VALUE + "," + APPLICATION_FORM_URLENCODED_VALUE))
.willReturn(aResponse()
.withStatus(HttpStatus.OK.value())
.withHeader(CONTENT_TYPE, "application/json")
.withHeader(CONNECTION, "Close")
.withBody("{\n" +
" \"access_token\": \"62466f2c-ff9e-4c6c-a866-b8296cf78041\",\n" +
" \"scope\": \"trust read write\",\n" +
" \"token_type\": \"bearer\",\n" +
" \"expires_in\": 20300,\n" +
"}")));
和
verify(postRequestedFor(urlPathEqualTo("/token")));
有一段日志,stubbed/actual 请求看起来相等,但是 Wiremock 说 Header does not match
:
有人能告诉我这里有什么问题吗?提前致谢!
对我来说,逗号后的 space 似乎是一个问题,请尝试:
.withHeader(ACCEPT, equalTo(APPLICATION_JSON_VALUE + ", " + APPLICATION_FORM_URLENCODED_VALUE))
顺便说一下,将 headers 与 equalTo
进行比较可能不太准确。您可以考虑使用 containing
:
post(urlPathEqualTo("/token"))
.withHeader(ACCEPT, containing(APPLICATION_JSON_VALUE))
.withHeader(ACCEPT, containing(APPLICATION_FORM_URLENCODED_VALUE))
我正在尝试断言在 OAuth2 流程中调用的先前存根端点:
stubFor(
post(urlPathEqualTo("/token"))
.withHeader(AUTHORIZATION, equalTo("Basic cGluLmFwaS5jbGllbnRJZDpwaW4uYXBpLmNsaWVudFNlY3JldA=="))
.withHeader(CONTENT_TYPE, equalTo("application/x-www-form-urlencoded;charset=UTF-8"))
.withHeader(ACCEPT, equalTo(APPLICATION_JSON_VALUE + "," + APPLICATION_FORM_URLENCODED_VALUE))
.willReturn(aResponse()
.withStatus(HttpStatus.OK.value())
.withHeader(CONTENT_TYPE, "application/json")
.withHeader(CONNECTION, "Close")
.withBody("{\n" +
" \"access_token\": \"62466f2c-ff9e-4c6c-a866-b8296cf78041\",\n" +
" \"scope\": \"trust read write\",\n" +
" \"token_type\": \"bearer\",\n" +
" \"expires_in\": 20300,\n" +
"}")));
和
verify(postRequestedFor(urlPathEqualTo("/token")));
有一段日志,stubbed/actual 请求看起来相等,但是 Wiremock 说 Header does not match
:
有人能告诉我这里有什么问题吗?提前致谢!
对我来说,逗号后的 space 似乎是一个问题,请尝试:
.withHeader(ACCEPT, equalTo(APPLICATION_JSON_VALUE + ", " + APPLICATION_FORM_URLENCODED_VALUE))
顺便说一下,将 headers 与 equalTo
进行比较可能不太准确。您可以考虑使用 containing
:
post(urlPathEqualTo("/token"))
.withHeader(ACCEPT, containing(APPLICATION_JSON_VALUE))
.withHeader(ACCEPT, containing(APPLICATION_FORM_URLENCODED_VALUE))