Get POST request three miscellaneous [turn: http://student.csdn.net/space.php? Uid = 22651 & Do = Blog & id = 10317]

Source: Internet
Author: User
Tags html header

Suddenly it seems like everything is understandable. Today, we will thoroughly understand the get and post problems.

HTTP defines different methods for interaction with the server. The most basic methods are get and post.

HTTP-GET and HTTP-POST are standard protocol verbs that use HTTP to encode and transmit variable name/variable value pair parameters and use the relevant request semantics. Each HTTP-GET and HTTP-POST is composed of a series of HTTP request headers that define what the client has requested from the server, and the response is composed of a series of HTTP Response Headers and response data, if the request is successful, a response is returned.
The HTTP-GET Passes parameters in the format of urlencoded text that uses the MIME type application/X-WWW-form-urlencoded. Urlencoding is a character encoding that ensures that transmitted parameters are composed of compliant texts. For example, the encoding of a space is "% 20 ". The additional parameter can also be considered as a query string.
Like a HTTP-GET, HTTP-POST parameters are URL encoded. However, the variable name/variable value is not transmitted as part of the URL, but is transmitted within the actual HTTP request message.

(1) get is to get data from the server, and post is to send data to the server.

(1) on the client side, the get method submits data through the URL, and the data can be seen in the URL. In the post mode, the data is placed in the HTML header for submission.

(2) 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.

(2) data submitted in get mode can contain a maximum of 1024 bytes, whereas post mode does not.

(3) security issues. As mentioned in (1), when get is used, the parameter is displayed in the address bar, but post is not. 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.

Note: security means that this operation is used to obtain information instead of modifying information. Idempotence means that multiple requests to the same URL should return the same result. The complete definition is not as strict as it looks. In other words, get requests generally do not have side effects. 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 returns the current 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 ).

Next, this problem

A small example of page value transfer:

Suppose there is a page named test. asp? Id = 111
The page here uses the get method. request. querystring ("ID") is the same as request ("ID"). If you do not specify a set of requests, the querystring will be searched first.

If the page uses the POST method to send data to test. ASP, then request. querystring ("ID") is useless (he can only get), but must use request. from ("ID"), and if you still use request ("ID"), he can also obtain data, but first checks the value of querystring, it is obviously slow.

The following is an example of Detection:
<%
If request ("Submit") <> "then
Response. Write "get directly:" & request ("username") & "<br>"
Response. Write "get:" & request. querystring ("username") & "<br>"
Response. Write "get post:" & request. Form ("username") & "<br>"
End if
%>
<Form name = form1 action = "" method = post>
<Input type = test name = "username" value = "postuser">
<Input type = submit name = "Submit" value = "test">
</Form>

 

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.