The difference between the form data in the HTTP request and the request payload

Source: Internet
Author: User

Ajax is often used in front-end development to send asynchronous requests, and requests for post types are included with the request data. The two commonly used methods are: Form Data and Request Payload.

GET request

When a GET request is used, the parameters are stitched together in the form of a key=value after the requested URL. For example:

Http://m.baidu.com/address/getlist.html?limit=50&offset=0&t=1502345139870

However, limited by the length of the request URL, a GET request is used when there are fewer general parameters.

POST request

When the number of parameters is high and there is a certain security requirement for the data, consideration is given to passing the parameter data with the POST request. The parameter data for the POST request is in the request body.

Mode one: Form data forms

When the request header of the POST request is set to content-type:application/x-www-form-urlencoded (the default), the parameters are submitted in the form of the standard form data in the request body, with the & sign stitching, the parameter format is key= Value&key=value&key=value ...

Front-End Code settings:

Xhr.setrequestheader (' Content-type ', ' application/x-www-form-urlencoded '); Xhr.send (' a=1&b=2&c= 3 ');

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

Mode two: Request payload form

If you use the Ajax native POST request, the request header is set to Content-type:application/json, the requested parameter is displayed in the request payload, the format of the parameter is in JSON format: {"key": "Value", "Key" : "Value" ...}, which is more readable in this way.

The backend can be obtained using the Getrequestpayload method.

Form Data and Request Payload differences

If the request header is set to content-type:application/x-www-form-urlencoded, then this request is considered a form request, the parameter appears in the form data, the format is key=value&key= Value&key=value ...

The native Ajax request header is set to Content-type:application/json, or the default content-type:text/plain is used, and the parameters are presented in the request payload block.

Reference Documentation:

Http://www.cnblogs.com/btgyoyo/p/6141480.html

http://xiaobaoqiu.github.io/blog/2014/09/04/form-data-vs-request-payload/

The difference between the form data in the HTTP request and the request payload

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.