放心:字符集问题 - 无法识别使用放心传递有效的 contentType 并且由于内容类型无效而给出错误

Dip*_*man 3 api automation rest-assured

放心版本:3.0.5

作为用户,我们已将 contentType 作为 XML 以以下格式传递并具有有效内容。

contentType(ContentType.XML) OR .contentType("application/xml")
Run Code Online (Sandbox Code Playgroud)

在应用程序中允许的内容类型是:“application/xml” 提供的内容类型反映如下。

Content-Type=application/xml; charset=ISO-8859-1
Run Code Online (Sandbox Code Playgroud)

因此,它给出了错误“内容类型无效”如何处理此用例。

Dip*_*man 5

正如预期的内容类型是 application/xml 但提供的内容类型对象包括“charset=ISO-8859-1”。因此,我们需要删除此字符集详细信息。

EncoderConfig encoderconfig = new EncoderConfig();
    Response response = given()
            .config(RestAssured.config()
                    .encoderConfig(encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false)))
            .contentType(ContentType.XML)
            .log().all().body(this.buildPayload()).when().
    post(...).
Run Code Online (Sandbox Code Playgroud)

...;

更多详情请参考以下链接:

https://github.com/rest-assured/rest-assured/wiki/Usage#avoid-adding-the-charset-to-content-type-header-automatically

https://groups.google.com/forum/#!topic/rest-assured/O74EgJWUSJY