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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.