我对包含JSON正文的发布请求使用放心
我的职位要求代码是:-
RestAssuredResponseImpl stat=
(RestAssuredResponseImpl)given().
header("Accept", "application/json").
header("Content-Type", "application/json").
header("userid", "131987”).
queryParam("name", "Test12").
queryParam("title", "Test127123").
queryParam("contactEmail", “abc@gmail.com").
queryParam("description", "testing purpose").
when().post("").thenReturn().getBody();
我收到以下错误:
{"errors":{"error":{"code":400,"type":"HttpMessageNotReadableException","message":"Required request body content is missing: org.springframework.web.method.HandlerMethod$HandlerMethodParameter@8e9299c"}}}
请帮助。
最佳答案
看起来您的服务器正在等待请求正文,但您正在将数据作为查询参数发送。如果我理解正确,则希望将数据作为JSON发送。最简单的方法是使用this方法:
Map<String, Object> jsonAsMap = new HashMap<>();
map.put("name", "Test12");
map.put("title", "Test127123");
map.put("contactEmail", “abc@gmail.com");
map.put("description", "testing purpose");
ResponseBody =
given().
accept(ContentType.JSON).
contentType(ContentType.JSON).
header("userid", "131987”).
body(jsonAsMap).
when().
post("").
thenReturn().body();
关于rest - 放心的POST请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31875534/