Open osandadeshan opened 6 years ago
Hi @osandadeshan, any updates on this? I'm yielding the same, with the same components, and as you said, works totally fine in Postman sending as form-data.
Managed to solve the issue by sending with contentType("multipart/form-data") instead of the form data provided by rest assured. Works exactly like in postman.
Like so:
protected Response doPostForm(String url, Map<String, String> formData) {
RequestSpecification req = startPostRequest();
req.contentType("multipart/form-data");
for (Map.Entry<String,String> entry : formData.entrySet())
{
String key = entry.getKey();
String value = entry.getValue();
req.multiPart(key, value);
}
return req.post(url);
}
Hi @osandadeshan, I solved the problem in the following way.
RestAssured.given().config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig().encodeContentTypeAs("multipart/form-data", ContentType.TEXT)))
.contentType("multipart/form-data; boundary=--MyBoundary")
.queryParams(params) // formParams does not working
.post(url)
Managed to solve the issue by sending with contentType("multipart/form-data") instead of the form data provided by rest assured. Works exactly like in postman.
Like so:
protected Response doPostForm(String url, Map<String, String> formData) { RequestSpecification req = startPostRequest(); req.contentType("multipart/form-data"); for (Map.Entry<String,String> entry : formData.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); req.multiPart(key, value); } return req.post(url); }
It works
I need to invoke a form-data typed API using Rest Assured. Here is my code.
When I execute this, I am getting the below error.
When I use
.config(RestAssured.config().encoderConfig(encoderConfig().encodeContentTypeAs("application/form-data", ContentType.TEXT)))
in theinvoke()
method, it gives the result as below.My request is not
x-www-form-urlencoded
type, it isform-data
type. I can execute it using postman.Appreciate your support on this.
Thanks.