Differences between http get/POST requests

Source: Internet
Author: User
Tags html header

HTTP Request: difference between get and post methods [conversion]

  1. HTTP defines different methods for interaction with the server. The most basic methods are get and post. In fact, get applies to most requests, while retaining post is only used to update sites. According to the HTTP specification, get is used for information retrieval and should beSecureAndIdempotent. The so-calledSecureThis operation is used to obtain information rather than modify information. In other words, get requests generally do not have side effects.IdempotentThis means that the same result should be returned for multiple requests of the same URL. The complete definition is not as strict as it looks. Basically, the goal is that when a user opens a link, she can be confident that the resource has not changed from her own perspective. For example, the front pages of news sites are constantly updated. Although the second request will return a different batch of news, this operation is still considered safe and idempotent because it always returnsCurrent News. And vice versa. POST requests are not that easy. Post indicates a request that may change resources on the server. Taking the news site as an example, the reader's comments to the article should be implemented through the POST request, because the site is already different after the annotation is submitted (for example, an annotation appears below the article );
  2. If method is not specified during form submission, the default value is get. The data submitted in form will be appended to the URL? Separated from the URL. The letter and number characters are sent as they are, but spaces are converted to "+". Other symbols are converted to % xx, XX represents the ASCII (or ISO Latin-1) value in hexadecimal notation. The data submitted for the GET request is placed in the HTTP Request Header, while the data submitted for the post is placed in the object data;
  3. Data submitted in get mode can contain a maximum of 1024 bytes, whereas post mode does not.

1. Get is to get data from the server, and post is to send data to the server.
2.Get adds the parameter data queue to the URL referred to by the Action attribute of the submission form. The values correspond to each field in the form one by one..Post uses the http post mechanism to place fields in the form and their content in the HTML header and send them to the URL address referred to by the Action attribute. You cannot see this process.
3.For the get method, the server uses request. querystring to obtain the value of the variable. For the POST method, the server uses request. Form to obtain the submitted data.
4. The data volume transmitted by get is small and cannot exceed 2 kb. The amount of data transmitted by post is large, which is generally not restricted by default. Theoretically, the maximum size of IIS4 is 80 KB, and that of iis5 is 100kb.
5. Low get security and high post security.

××××××××××××××××××××××××××××××××××××××××××× *

1. The encoding used when the two parameters are passed is not necessarily the same. In tomcat, it seems that the get encoding method is based on the encoding method specified on the page, while post is always using the same encoding method, which can be configured in Tomcat server. xml.

2. When get is used, parameters are displayed in the address bar, but not post.

Therefore, if the data is Chinese and non-sensitive, use get. If the data you enter is not Chinese characters and contains sensitive data, use post as well.

××××××××××××××××××××××××××××××××××××××××××× *



UsePostAnd useGetDifference (ASP)

I, In form, you can use post or get. They are all valid values of method. However, the post and get methods are at least two different in use:

1. The get method transmits user input through URL requests. The post method is in another form.

2. You need to use request. querystring to obtain the value of the variable for get-based submission. When using post-based submission, you must use request. Form to access the submitted content.

 

Study the following code carefully. You can run it to feel it:

 

Code

<! -- Two forms have different method Attributes -->

<Form action = "getpost. asp" method = "get">

<Input type = "text" name = "text" value = "Hello World"> </input>

<Input type = "Submit" value = "method = get"> </input>

</Form>

<Br>

<Form action = "getpost. asp" method = "Post">

<Input type = "text" name = "text" value = "Hello World"> </input>

<Input type = "Submit" value = "method = post"> </input>

</Form>

 

<Br>

<Br>

 

<% If request. querystring ("text") <> "" Then %>

The string passed through the get method is: "<B> <% = request. querystring (" text ") %> </B>" <br>

<% End if %>

 

<% If request. Form ("text") <> "" Then %>

The string passed through the POST method is: "<B> <% = request. Form (" text ") %> </B>" <br>

<% End if %>

 

Description

Save the above Code as getpost. asp and run it. First test the POST method. At this time, the URL of the browser does not change, and the returned result is:

The string passed through the POST method is: "Hello World"

Then test the submission using the get method. Note that the URL of the browser is changed:

Http: // localhost/General/form/getpost. asp? TEXT = Hello + world

The returned result is:

The string passed through the get method is: "Hello World"

Finally, submit the file through the POST method. The URL of the browser is:

Http: // localhost/General/form/getpost. asp? TEXT = Hello + world

The returned result is:

The string passed through the get method is: "Hello World"

The string passed through the POST method is: "Hello World"

 

Prompt

Submitting data through the get method may cause security issues. For example, a login page. When you submit data using the get method, the user name and password will appear on the URL. If:

1. the login page can be cached by the browser;

2. Others can access the customer's machine.

Then, others can read the customer's account and password from the browser's history. Therefore, in some cases, the get method may cause serious security problems.

 

Suggestion: In form, the POST method is recommended.

 

II,<Form action = "" method = "Post">A prompt box will pop up when refreshing, asking if to resend the request. If it is changed to method = getThis prompt is not displayed,The following are some differences between post and get.

 

The post request has no length limit (at least theoretically)

Get has a length limit of up to 2048 bytes (1024 Chinese characters)

 

III,Do you still remember request. querystring ()? As long as the value is transmitted using get, it will be followed by the HTTP request string! Try it! Post is not followed by the HTTP request string, but at the end of the request! And invisible. Generally, the password must be passed in like this. Otherwise, you can see it directly in the address bar !! (Although not encrypted)

There is also more post-uploaded content.

Generally, IIS filters only accept get parameters.This is why the large search engines are followed by a lot of content, because post cannot be sent in the past, and only get can be used. Check out Goole or Yahoo!

 

 



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.