java - 如何放心地将布尔值作为 json 正文发送
问题描述
我有一个 PUT 服务,其中请求正文为真或假。该服务在 Postman 中运行良好,Content-Type 为 application/json。但是当我尝试使用 Rest-Assured 时它失败了,并且我收到错误消息“A JSONObject 文本必须以 '{' 开头”
下面是我的代码:
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();
如果您知道任何解决方案,请告诉我。
解决方案
单独的原语不是有效的 json,您已指定它是 via contentType(ContentType.JSON)
。
主体必须是对象/映射或对象/映射数组。
尝试
.body(Map.of("value", true))
推荐阅读
- c# - 在 Unity2D 中管理 NPC
- fail2ban - fail2ban 中的多个插值操作
- ios - 尝试使用 Alamofire 解析 API 响应时出错
- python - awk 命令在 /bin/sh -c 下不起作用
- angular - Angular中的登录页面重新路由
- nestjs - 如何在 typeOrm 中获得我的关系 dto?
- sphinxsearch - 狮身人面像搜索:如何理解 min_prefix_len
- jquery - 如何连接 2 个与 OR 运算符相同的 jquery 函数?
- python - 使用 INSTALOADER 如何添加配置文件列表?现在我得一一写
- python - 有没有办法通过在 vscode 中输入 python 模块的名称来直接获取导入