rest - RestAssured: '没有在响应中指定支持的 Content-Type。对于支持的内容类型,Content-Type 为 'text/html;charset=ISO-8859-1''
问题描述
我期待服务器上出现此请求的错误,然后将其作为字符串与预期响应进行比较。
return given()
.queryParams(incorrectParams)
.when()
.put("https://example.com/endpoint")
.then()
.statusCode(500)
.extract().body().as(String.class)
问题是 RestAssured 在执行此操作时给了我一个错误:java.lang.IllegalStateException: Cannot parse object because no supported Content-Type is specified in response。内容类型是'text/html;charset=ISO-8859-1'。
我已在设置中添加了解码器,但它无济于事。
RestAssured.config().decoderConfig(new DecoderConfig(ContentType.HTML.withCharset(Charset.forName("ISO-8859-1"))));
错误情况下服务器返回的类型为:Content-Type: text/html;charset=ISO-8859-1
我还在调试器中看到默认解码器应该支持这样的响应。
还要提一件事 - 如果在 queryParams 中使用正确的参数发送请求,则返回 Content-Type: application/json 并且对于正面测试用例来说一切正常。
如何正确处理(提取)这样的响应?被保险人应该设置什么?
放心版本是4.4.0
解决方案
只是为了将响应保存为字符串,您可以这样做。
.then()
.statusCode(500)
.extract().asString()
推荐阅读
- python - 使用 .isin() pandas (python) 测试的列中的替代值
- html - 如何防止div内的属性使用项目的css
- mysql - 用引号更新部分文本
- macos - 在 MacOS 中更改硬盘驱动器的图标时 - icns 文件实际存储在哪里?
- powershell - Powershell Get-Acl 用于没有访问权限的文件夹
- r - 如何更改 scale() 阻止的列名
- javascript - React/Redux - 何时使用状态和道具/何时更改道具
- aem - AEM Query Builder:需要在所有页面上的所有属性上搜索特定文本
- python - Git Pycharm 仅将本地 master 分支更改为与 origin master 分支完全相同
- r - 使用 R 中的“个性化”顺序对向量进行排序