Api 如何使用restasured测试无效的编码REST响应

Api 如何使用restasured测试无效的编码REST响应,api,testing,rest-assured,Api,Testing,Rest Assured,当请求中指定了无效编码时,我试图测试API返回的错误消息。 我正在发送带有纯文本正文和内容类型标题“application/html”的POST请求。我能从邮递员那里成功地做到这一点。 但是,重新启动提示以直接指定编码 Don't know how to encode {...} as a byte stream. Please use EncoderConfig (EncoderConfig#encodeContentTypeAs) to specify how to serialize d

当请求中指定了无效编码时,我试图测试API返回的错误消息。 我正在发送带有纯文本正文和内容类型标题“application/html”的POST请求。我能从邮递员那里成功地做到这一点。 但是,重新启动提示以直接指定编码

Don't know how to encode  {...} as a byte stream.
Please use EncoderConfig (EncoderConfig#encodeContentTypeAs) to specify how to serialize data for this content-type.
For example: "given().config(RestAssured.config().encoderConfig(encoderConfig().encodeContentTypeAs("application/html", ContentType.TEXT))). .."
但即使我直接这么做了,我也会从重启中得到同样的错误:

RestAssured.given().config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig().encodeContentTypeAs("application/html", ContentType.HTML)));
以下是我使用的标题:

RestAssured.given().header("Content-Type", "application/html")

.header("accept", "application/json");

您可以设置请求的响应类型,还可以使用以下代码验证响应的内容类型

given().contentType("application/json; charset=utf-8").when().get("http://localhost:3000/posts/").then().statusCode(200)
        .and().contentType("application/json; charset=utf-8");