[英]How to send boolean as a json body in rest-assured
I have a PUT service where the request body is either true or false.我有一个 PUT 服务,其中请求正文为真或假。 The service is working fine in Postman with Content-Type as application/json.
该服务在 Postman 中运行良好,Content-Type 为 application/json。 But it is failing when I try the same with Rest-Assured and I am getting the error saying 'A JSONObject text must begin with '{' '
但是当我尝试使用 Rest-Assured 时它失败了,并且我收到错误消息“A JSONObject 文本必须以 '{' 开头”
below is my code:下面是我的代码:
RestAssured.given()
.contentType(ContentType.JSON)
.accept(ContentType.ANY)
.body(true)
.put(sUrl)
.then().log().ifError()
.statusCode(Matchers.greaterThanOrEqualTo(200))
.statusCode(Matchers.lessThanOrEqualTo(299))
.extract()
.response();
Let me know if you are aware of any solution for this.如果您知道任何解决方案,请告诉我。
A solitary primitive is not valid json, which you have specified it is via contentType(ContentType.JSON)
.单独的原语是无效的 json,您已通过
contentType(ContentType.JSON)
指定它。
The body must either be an object/map or an array of objects/maps.主体必须是对象/映射或对象/映射数组。
Try尝试
.body(Map.of("value", true))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.