GET request parameters are spliced after the url. This method is called query parameters. In fact, POST requests can also be requested using the query parameter.
2. Browser behavior: Form submission
action: url Address, the address where the server receives form data method: Submit server's http Method, generally post and get name: Best delicious name Uniqueness of attributes enctype: The code type used when submitting form data. It is used by default"pplication/x-www-form-urlencoded"，If used POST Request, the content-type The specified value is the value. If there are uploaded files in the form, the code type needs to be used"multipart/form-data"，Type to complete the transfer of file data.
The data submitted by POST must be placed in the message body, but the protocol does not specify what encoding method the data must use. In fact, developers can decide the format of the message body by themselves, as long as the last HTTP request meets the above format.
However, it is meaningful for the server to parse the data successfully. General server languages, such as php, python, and their framework, have built-in functions to automatically parse common data formats. The server usually knows how the message body in the request is encoded according to the content type field in the request header, and then parses the body.
Therefore, when it comes to the POST submission data scheme, it includes two parts: content type and message body coding method.
The data of the form will be processed into a message, with labels as units and separated by separators. You can upload both key value pairs and files.
<FORM method="POST" action="http://w.sohu.com/t2/upload.do" enctype="multipart/form-data"> <INPUT type="text" name="city" value="Santa colo"> <INPUT type="text" name="desc"> <INPUT type="file" name="pic"> </FORM>
POST /t2/upload.do HTTP/1.1 User-Agent: SOHUWapRebot Accept-Language: zh-cn,zh;q=0.5 Accept-Charset: GBK,utf-8;q=0.7,*;q=0.7 Connection: keep-alive Content-Length: 60408 Content-Type:multipart/form-data; boundary=ZnGpDtePMx0KrHh_G0X99Yef9r8JZsRJSXC Host: w.sohu.com --ZnGpDtePMx0KrHh_G0X99Yef9r8JZsRJSXC Content-Disposition: form-data; name="city" Santa colo --ZnGpDtePMx0KrHh_G0X99Yef9r8JZsRJSXC Content-Disposition: form-data;name="desc" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... --ZnGpDtePMx0KrHh_G0X99Yef9r8JZsRJSXC Content-Disposition: form-data;name="pic"; filename="photo.jpg" Content-Type: application/octet-stream Content-Transfer-Encoding: binary ... binary data of the jpg ... --ZnGpDtePMx0KrHh_G0X99Yef9r8JZsRJSXC--
- The content type is multipart / form data, and a boundary will be generated later for segmentation.
- Each part starts with -- boundary and must contain a content disposition header. Other header information is optional, such as content type. When uploading a file, content type is the specific file type.
- Content disposition contains type and a parameter named name. Type is form data. The value of the name parameter is the name of the form control (i.e. field). If it is a file, there is also a filename parameter. The value is the file name.
- If the file content is obtained by filling in the form, the content type will be automatically set (recognized) to the corresponding format when uploading. If it cannot be recognized, it will be set to "application / octet stream"; If multiple files are filled into a single form item, their request format will be multipart/mixed; If the content of a Part is different from the default encoding method, there will be a "content transfer encoding" header to specify;
- This is followed by the content description information, then carriage return, and finally the specific content of the field (text or binary).
- If you are transferring a file, you should also include the file name and file type information. The message body ends with -- boundary --.
application/x-www-from-urlencoded will convert the data in the form into key value pairs, for example, name = Java & age = 23
This code is used by default for the post request form.
Application / octet stream, which literally means that only binary data can be uploaded. It is usually used to upload files. Since there is no key value, only one file can be uploaded at a time.