我如何在Spring Boot测试中指定mediatype为textplain;charset=UTF-8?

问题描述 投票:0回答:2

这是我的测试。

 @Test
 fun `test config properties`() {
    mockMvc.request(HttpMethod.GET,"someUrl") {
        accept = MediaType.TEXT_PLAIN
    }.andExpect {
        status { isOk }
        content { contentType(MediaType.TEXT_PLAIN) }
    }
}

但它失败了。

预期:textplain 实际:textplain;charset=UTF-8

这是在使用Kotlin DSL for MockMVC。

我如何将accept改为允许使用charset=UTF-8?

spring spring-boot spring-mvc kotlin mockmvc
2个回答
1
投票

有一个工厂方法可以接受自定义值。试试。

MediaType.valueOf("text/plain;charset=UTF-8")
© www.soinside.com 2019 - 2024. All rights reserved.