HTTP request: The difference between get and post methods

Source: Internet
Author: User
Tags html header

First version:
HTTP defines different ways to interact with the server, and the most basic method is GET and POST.
In fact GET applies to most requests, while retaining POST is only used to update the site. According to the HTTP specification, get is used for information acquisition and should be secure and idempotent. The so-called security means that the operation is used to obtain information rather than modify information. In other words, GET requests generally should not have side effects. Idempotent means that multiple requests to the same URL should return the same result. The complete definition is not as strict as it seems. Fundamentally, the goal is that when a user opens a link, it can be sure that the resource is not changed from its point of view. For example, the front page of news sites is constantly being updated. Although the second request returns a different batch of news, the operation is still considered safe and idempotent, as it always returns the current news. Vice versa.
The POST request is not that easy. POST represents a request that might change resources on the server. Still take the news site as an example, the reader's comments on the article should be implemented through a POST request, because the site is different after the comment is submitted (for example, a note appears below the article);
When the form is submitted, if you do not specify method, the default is a GET request, and the data submitted in the form will be appended to the URL, separated from the URL. The alphanumeric character is sent as is, but the space is converted to the "+" sign, and the other symbol is converted to%XX, where XX is the ASCII (or ISO Latin-1) value that the symbol is represented in 16 binary. The GET request submits the data to be placed in the HTTP request protocol header, and the data submitted by the post is placed in the Entity data;
The Get method submits only 1024 bytes of data, while Post does not have this limit.

The second version:
1) Get gets the data from the server and post is the data that is sent to the server.
(1) On the client side, the Get method submits the data through the URL, the data can be seen in the URL, the Post method, and the data is placed within the HTML header submission.
(2) for Get mode, the server side uses Request.QueryString to get the value of the variable, for the Post method, the server side uses Request.Form to obtain the submitted data.
(2) The data submitted by the Get method can only have up to 1024 bytes, while post does not have this limit.
(3) Security issues. As mentioned in (1), when you use Get, the parameters are displayed on the address bar, and Post does not. So, if the data is in Chinese and is non-sensitive, then use get; If the user enters data that is not a Chinese character and contains sensitive data, then it is better to use post.
Here's a simple example to illustrate their differences:
<-submit forms by Get and post respectively--
<form action= "getpost.asp" method= "Get" >
< INPUT type= "text" value= "http://wxf0701.cnblogs.com//>
< INPUT type= "submit" value= "Get Method" ></INPUT>
</form>
< br>
< FORM action= "getpost.asp" method= "POST" >
< INPUT type= "text" value= "http://wxf0701.cnblogs.com/>
< INPUT type= "submit" value= "Post mode" ></INPUT>
</form>
< br>
<% If Request.QueryString ("Text") <> "then%>
The string passed by the Get method is: "<b><%= request.querystring (" Text ")%></b>" <BR>
<% End If%>
<% If Request.Form ("Text") <> "then%>
The string passed by post is: "<b><%= request.form (" Text ")%></b>" <BR>
<% End If%>

Third version:
The Get and post methods in the form, respectively, correspond to the Get and post methods in the HTTP protocol during data transfer. The main differences are as follows:
1, get is used to obtain data from the server, and post is used to pass data to the server.
2. Get adds the data in the form in the form of Variable=value, followed by the URL to which the action points, and both use "?". connections, and each variable is connected by a "&" connection; Post is the data in the form that is placed in the data body of the forms, in the same way that the variables and values are passed to the URL that the action points to.
3, get is not safe, because in the transmission process, the data is placed in the requested URL, and now many existing servers, proxy servers or user agents will log the request URL to the journal file, and then put in a place, so that there may be some privacy information to be seen by third parties. In addition, users can see the submitted data directly in the browser, and some system internal messages will be displayed in front of the user. All the actions of the post are not visible to the user.
4, get transmission of small amount of data, mainly because of the URL length limit, and post can transfer a large amount of data, so the upload file can only use post (of course, there is a reason, will be mentioned later).
5. Get restricts the value of the data set for form forms to be ASCII characters, while Post supports the entire ISO10646 character set.
6, get is the default method for form.
The action quotes are in the path method, such as sending to a mailbox or other Web page or something.

HTTP request: The difference between get and post methods

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.