{"id":322215,"date":"2021-02-05T02:35:56","date_gmt":"2021-02-04T18:35:56","guid":{"rendered":"http:\/\/4563.org\/?p=322215"},"modified":"2021-02-05T02:35:56","modified_gmt":"2021-02-04T18:35:56","slug":"mockmvcresponse%ef%bc%8c%e4%b8%ad%e6%96%87%e4%b9%b1%e7%a0%81","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=322215","title":{"rendered":"mockMvcResponse\uff0c\u4e2d\u6587\u4e71\u7801"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  mockMvcResponse\uff0c\u4e2d\u6587\u4e71\u7801               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : beichenhpy <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h1>\u4ee3\u7801\u5982\u4e0b<\/h1>\n<p> <\/p>\n<pre><code>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\"); <\/code><\/pre>\n<h2>\u8bbe\u7f6e\u4e86 utf-8 \u4e86\uff0cidea \u63a7\u5236\u53f0\u6253\u5370\u7ed3\u679c<\/h2>\n<pre><code>MockHttpServletResponse:            Status = 200     Error message = null           Headers = [Content-Type:\"application\/json\"]      Content type = application\/json              Body = {\"code\":200,\"result\":\"\u00e5\u0085\u0081\u00e8\u00ae\u00b8\u00e8\u00bf\u009b\u00e5\u0085\u00a5\"}     Forwarded URL = null    Redirected URL = null           Cookies = [] <\/code><\/pre>\n<h2>\u4f7f\u7528 HTTP-CLIENT \u8fd4\u56de\u6b63\u5e38<\/h2>\n<pre><code>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\": \"\u5141\u8bb8\u8fdb\u5165\" } <\/code><\/pre>\n<p>\u4e0d\u77e5\u9053\u600e\u4e48\u529e\u4e86\u3002\u3002\u6c42\u52a9<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5201847\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : beichenhpy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u81ea\u5df1\u89e3\u51b3\u4e86\uff0c\u679c\u7136\u88ab\u964d\u6743\u7684\u6211\u6ca1\u4eba\u56de\u7b54<br \/>https:\/\/stackoverflow.com\/questions\/58525387\/mockmvc-no-longer-handles-utf-8-characters-with-spring-boot-2-2-0-release                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5201848\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Jrue0011 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u662f\u76f4\u63a5\u53c2\u8003 MockMvcResultHandlers.PrintWriterPrintingResultHandler \u5199\u4e86\u4e00\u4e2a\u76f4\u63a5\u6307\u5b9a Charset \u7684 PrintingResultHandler \u5b50\u7c7b\u7136\u540e\u5728\u6d4b\u8bd5\u91cc\u7528\uff0c\u800c\u4e0d\u7528 MockMvcResultHandlers.print()&#8230;<\/p>\n<p>https:\/\/paste.ubuntu.com\/p\/dmsjmqWm5W\/                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5201849\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Jrue0011 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u8fc7 MockHttpServletRequest \u548c MockHttpServletResponse \u8bbe\u7f6e CharacterEncoding \u7684\u65f6\u5019\u4f1a\u66f4\u65b0 ContentType&#8230;<br \/>\u6240\u4ee5\u5982\u679c\u6709\u8c03\u7528 andExpect \u5bf9\u6bd4 ContentType \u7684\u8bdd\uff0c\u6bd4\u5982<\/p>\n<p>andExpect(content().contentType(MediaType.APPLICATION_JSON))<\/p>\n<p>\u5f97\u653e\u5728 andDo \u524d\u9762&#8230;                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>mockMvcResponse\uff0c\u4e2d&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/322215"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=322215"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/322215\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=322215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=322215"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=322215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}