The way in which the contenttype parameters in the AJAX POST request are captured in the servlet as form data and request payload

Source: Internet
Author: User
Tags webp chrome developer chrome developer tools

Turn from: https://blog.csdn.net/mhmyqn/article/details/25561535

In an HTTP request, if it is a GET request, the form parameter is appended to the URL in name=value&name1=value1 form and, if it is a POST request, the form parameter is in the request body and is also name=value&name1= The Value1 form is in the request body. From the Chrome developer tools you can see the following (here is the readable form, not the actual request format of the HTTP request protocol):

GET Request:[Plain]  View Plain  copy requesturl:http://127.0.0.1:8080/test/test.do?name=mikan&address=street    request method:get   status code:200 ok       Request  Headers   accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8    accept-encoding:gzip,deflate,sdch   accept-language:zh-cn,zh;q=0.8,en;q=0.6   alexatoolbar-alx_ns_ph:alexatoolbar/alxg-3.2   connection:keep-alive   Cookie:JSESSIONID= 74ac93f9f572980b6fc10474cd8edd8d   host:127.0.0.1:8080   Referer:http://127.0.0.1:8080/test/ index.jsp   user-agent:mozilla/5.0  (windows nt 6.1) applewebkit/537.36  (KHTML,  like gecko)  Chrome/33.0.1750.149 Safari/537.36       query  string parameters   name:mikan   address:street       Response  headers   content-length:2   date:sun, 11 may 2014 10:42:38 gmt    server:apache-coyote/1.1  

POST request:[Plain]  View Plain  copy requesturl:http://127.0.0.1:8080/test/test.do   request method:post    status code:200 ok       request headers   Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8   Accept-Encoding:gzip, deflate,sdch   accept-language:zh-cn,zh;q=0.8,en;q=0.6   AlexaToolbar-ALX_NS_PH:AlexaToolbar /alxg-3.2   cache-control:max-age=0   connection:keep-alive   Content-Length:25    content-type:application/x-www-form-urlencoded   cookie:jsessionid= 74ac93f9f572980b6fc10474cd8edd8d   host:127.0.0.1:8080   Origin:http://127.0.0.1:8080    referer:http://127.0.0.1:8080/test/index.jsp   user-agent:mozilla/5.0  (Windows NT  6.1) applewebkit/537.36  (Khtml, like gecko)  chrome/33.0.1750.149 safari/537.36        form data   name:mikan   address:street       response  headers   content-length:2   DATE:SUN, 11 MAY 2014 11:05:33 GMT    server:apache-coyote/1.1  

Notice here that the content-type of the POST request is application/x-www-form-urlencoded, and the parameter is in the request body, the form Data in the request above.

In the servlet, you can get form parameters in the form of Request.getparameter (name).

And if you use native Ajax Post requests:[JavaScript]  View plain  copy function getxmlhttprequest ()  {              var xhr;              if (window. ActiveXObject)  {                       xhr= new activexobject ("Microsoft.XMLHTTP");             }else if  (window. XMLHttpRequest)  {                       xhr= new xmlhttprequest ();              }else {                       xhr= null;  

Related Article

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.