As the title says I have to stub a post request with request body in the form of form data. No json, string, or xml. I am using junit and wiremock's java api.
I am doing something like the following:
wireMockServer.stubFor(post(urlEqualTo(MY_URI))
.withRequestBody(
// how do I stub a body in form data format??
).willReturn(aResponse().withStatus(200).withHeader("content-type", "application/json").withBody(expectedBody))
);
any ideas of what to put in the code instead of the comment?
Thank you!
There isn't a specific form matcher in WireMock right now (there should be and I keep meaning to work on it). However, you can do something like this:
wireMockServer.stubFor(post(MY_URI)
.withRequestBody(containing("key1=value1"))
.withRequestBody(containing("key2=value2"))
.willReturn(okJson(expectedResponse));
Note, you'll need to URL encode value1, value2 etc. if there are any metacharacters in there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With