{"id":574,"date":"2022-07-16T10:31:00","date_gmt":"2022-07-16T02:31:00","guid":{"rendered":"http:\/\/blog.nonot.cn\/?p=574"},"modified":"2024-07-08T12:47:25","modified_gmt":"2024-07-08T04:47:25","slug":"java%e8%8e%b7%e5%8f%96http%e8%af%b7%e6%b1%82%e7%9a%84header%e5%92%8cbody%e7%9a%84%e7%ae%80%e5%8d%95%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blog.nonot.cn\/index.php\/2022\/07\/16\/java%e8%8e%b7%e5%8f%96http%e8%af%b7%e6%b1%82%e7%9a%84header%e5%92%8cbody%e7%9a%84%e7%ae%80%e5%8d%95%e6%96%b9%e6%b3%95\/","title":{"rendered":"java\u83b7\u53d6http\u8bf7\u6c42\u7684Header\u548cBody\u7684\u7b80\u5355\u65b9\u6cd5"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728http\u8bf7\u6c42\u4e2d\uff0c\u6709Header\u548cBody\u4e4b\u5206\uff0c\u8bfb\u53d6header\u4f7f\u7528request.getHeader(&#8220;&#8230;&#8221;);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bfb\u53d6Body\u4f7f\u7528request.getReader()\uff0c\u4f46getReader\u83b7\u53d6\u7684\u662fBufferedReader\uff0c\u9700\u8981\u628a\u5b83\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\uff0c\u4e0b\u9762\u662f\u8f6c\u6362\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n<pre class=\"lang:default decode:true  \">public class TestController {\n \n  @RequestMapping(\"\/a\")\n  protected void doPost(HttpServletRequest request,\n      HttpServletResponse response, BufferedReader br)\n      throws ServletException, IOException {\n\/\/Header\u90e8\u5206\n    System.out.print(request.getHeaderNames());\n    Enumeration&lt;?&gt; enum1 = request.getHeaderNames();\n    while (enum1.hasMoreElements()) {\n      String key = (String) enum1.nextElement();\n      String value = request.getHeader(key);\n      System.out.println(key + \"\\t\" + value);\n    }\n\/\/body\u90e8\u5206\n    String inputLine;\n    String str = \"\";\n    try {\n      while ((inputLine = br.readLine()) != null) {\n        str += inputLine;\n      }\n      br.close();\n    } catch (IOException e) {\n      System.out.println(\"IOException: \" + e);\n    }\n    System.out.println(\"str:\" + str);\n  }<\/pre>\n<p>\u00a0<\/p>","protected":false},"excerpt":{"rendered":"<p>\u5728http\u8bf7\u6c42\u4e2d\uff0c\u6709Header\u548cBody\u4e4b\u5206\uff0c\u8bfb\u53d6head&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-574","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/comments?post=574"}],"version-history":[{"count":1,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/574\/revisions"}],"predecessor-version":[{"id":1188,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/574\/revisions\/1188"}],"wp:attachment":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/media?parent=574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/categories?post=574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/tags?post=574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}