mockMvcResponse,中文乱码
資深大佬 : beichenhpy 1
代码如下
mockMvc .perform(MockMvcRequestBuilders .post("/mock/post") .content(JSON.toJSONString(person1)) .contentType(MediaType.APPLICATION_JSON) .header("X-Access-token", "1")) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcResultHandlers.print()) .andReturn().getResponse().setCharacterEncoding("UTF-8");
设置了 utf-8 了,idea 控制台打印结果
MockHttpServletResponse: Status = 200 Error message = null Headers = [Content-Type:"application/json"] Content type = application/json Body = {"code":200,"result":"å
许è¿å
¥"} Forwarded URL = null Redirected URL = null Cookies = []
使用 HTTP-CLIENT 返回正常
HTTP/1.1 200 Content-Type: application/json Transfer-Encoding: chunked Date: Wed, 03 Feb 2021 03:13:42 GMT Keep-Alive: timeout=60 Connection: keep-alive { "code": 200, "result": "允许进入" }
不知道怎么办了。。求助
大佬有話說 (3)