Java gets the header and body of the HTTP request

Source: Internet
Author: User

In the HTTP request, there is the header and the body of the points, read the header using Request.getheader ("...");

The read body uses Request.getreader (), but Getreader gets the BufferedReader and needs to convert it to a string, the following is the method of conversion.

 Public classTestController {@RequestMapping ("/A")    protected voidDoPost (httpservletrequest request, httpservletresponse response, BufferedReader BR)throwsServletexception, IOException {
Header section System.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 PartString 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); }

Java gets the header and body of the HTTP request

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.