I am using rest assured for the post request containing the JSON body
My post request code is :-
RestAssuredResponseImpl stat=
(RestAssuredResponseImpl)given().
header("Accept", "application/json").
header("Content-Type", "application/json").
header("userid", "131987”).
queryParam("name", "Test12").
queryParam("title", "Test127123").
queryParam("contactEmail", “[email protected]").
queryParam("description", "testing purpose").
when().post("").thenReturn().getBody();
I am getting the following error:-
{"errors":{"error":{"code":400,"type":"HttpMessageNotReadableException","message":"Required request body content is missing: org.springframework.web.method.HandlerMethod$HandlerMethodParameter@8e9299c"}}}
Kindly help....
Looks like your server is expecting a request body but you're sending the data as query parameters. If I understand it correctly you want to send your data as JSON. The easiest way to do this is using this approach:
Map<String, Object> map = new HashMap<>();
map.put("name", "Test12");
map.put("title", "Test127123");
map.put("contactEmail", "[email protected]");
map.put("description", "testing purpose");
ResponseBody =
given().
accept(ContentType.JSON).
contentType(ContentType.JSON).
header("userid", "131987").
body(map).
when().
post("").
thenReturn().body();
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