The difference between the two data transmission methods of method = post / get in form


Form provides two ways of data transmission — get and post. Although they are data submission methods, they are very different in actual transmission, and may have a serious impact on data. Although the web container has shielded some differences between the two in order to get the variable values conveniently, it will be helpful to understand the differences in the future programming.

The get and post methods in form correspond to the get and post methods in HTTP protocol respectively during data transmission. The main differences are as follows:

1. Get is used to get data from the server, while post is used to transfer data to the server.

2. Get adds the data in the form of variable = value to the URL that action points to, and the two use “?” connection, while the variables use “&” connection; post puts the data in the form in the data body of the form, and passes it to the URL that action points to according to the corresponding way of variable and value.

3. Get is not secure, because in the process of transmission, the data is put in the requested URL, and now many existing servers, proxy servers or user agents will record the requested URL to the log file, and then put it in a certain place, so that some private information may be seen by the third party. In addition, users can also see the submitted data directly in the browser, and some system internal messages will be displayed in front of users. All post operations are invisible to users.

4. Get transfers a small amount of data, which is mainly due to the limitation of URL length; post can transfer a large amount of data, so you can only use post when uploading files (of course, there is another reason, which will be mentioned later).

5. Get restricts the data set of form form to ASCII characters, while post supports the whole ISO10646 character set.

6. Get is the default method for form.

The data transmitted by post can be correctly converted into Chinese by setting encoding, while the data transmitted by get has no change. In future procedures, we must pay attention to this point.


1. The get method passes the user’s data through URL request, connects the name of each field in the form with its content in pairs of strings, and places it after the URL of the program indicated by the action attribute, such as , the data will be directly displayed on the URL, just like the user clicking on a link; the post method uses HTTP post The name of each field in the form and its content are placed in the HTML header and sent to the server, which is processed by the program indicated by the action attribute. The program will read and process the data of the form through stdin

2. Get method needs to use Request.QueryString To get the value of the variable, while the post method uses the Request.Form To access the submitted content

3. The amount of data transmitted by get method is very small, generally limited to about 2 kb, but the execution efficiency is better than that of post method; while the amount of data transmitted by post method is relatively large, it is waiting for the server to read the data, but there are byte restrictions, which is to avoid malicious attacks on the server with large amounts of data. According to Microsoft, Microsoft uses the Request.Form () the maximum data that can be received is limited, 80 kb in IIS 4 and 100 kb in IIS 5

Suggestion: unless you are sure that the data you submit can be submitted at one time, please try to use the post method

4. Submitting data in get mode will bring security problems, such as a landing page. When submitting data in get mode, the user name and password will appear on the URL. If the page can be cached or other people can access the client’s machine, the user’s account and password can be obtained from the historical records. Therefore, it is recommended to use post method for form submission Method to submit the form page. The common problem is that if the page is refreshed, a dialog box will pop up

proposal: for security reasons, it is recommended to use post to submit data