We all know that POST is generally used to submit data to the server. The four formats of POST submitted data are the four forms of Content-Type. Pay special attention to the format of the data in the body when http sends a request in each format. The 4 forms are:
1. application/x-www-form-urlencoded: URL encoded.
2. multipart/form-data: key-value pair data.
3. application/json: Json type data.
4. text/xml: xml.
The HTTP request methods specified by the HTTP/1.1 protocol include OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, and CONNECT. POST is usually used to submit data to the server, mainly used to submit forms and upload files.
The HTTP protocol is transmitted in ASCII code and is an application layer specification based on the TCP/IP protocol. The specification divides HTTP requests into four parts: request line, request header, blank line, and request body. Something like this:
The protocol stipulates that the data submitted by POST must be placed in the message body (entity-body), but the protocol does not specify what encoding method the data must use. In fact, developers can completely decide the format of the message body by themselves, as long as the last HTTP request sent meets the above format.
But when the data is sent out, it only makes sense if the server parses it successfully. General server-side languages such as PHP, Python, etc., and their frameworks have built-in functions for automatically parsing common data formats. The server usually learns how the message body in the request is encoded based on the Content-Type field in the request headers, and then parses the body. So when it comes to the POST submission data scheme, it includes two parts: Content-Type and message body encoding method. We will officially introduce them below.
application/x-www-form-urlencoded
Introduction
This is the most common way to submit data via POST. If the browser’s native