In http request, there are differences between header and Body. Use request.getHeader("...");
Reading Body uses request.getReader(), but getReader gets the BufferedReader, which needs to be converted into a string. The following is the conversion method.
public class TestController { @RequestMapping("/a") protected void doPost(HttpServletRequest request, HttpServletResponse response, BufferedReader br) throws ServletException, IOException {//Header partSystem.out.print(request.getHeaderNames()); Enumeration<?> enum1 = request.getHeaderNames(); while (enum1.hasMoreElements()) { String key = (String) enum1.nextElement(); String value = request.getHeader(key); System.out.println(key + "/t" + value); }//body part String inputLine; String str = ""; try { while ((inputLine = br.readLine()) != null) { str += inputLine; } br.close(); } catch (IOException e) { System.out.println("IOException: " + e); } System.out.println("str:" + str); }The above is the entire content of the simple method of obtaining the header and body of http requests from Java brought to you by the editor. I hope everyone will support Wulin.com more~