Differences between http get post

Source: Internet
Author: User
Tags html header

 

1. http request format:

<Request line>

<Headers>

<Blank line>

[<Request-body>]

In an HTTP request, the first line must be a request line to describe the request type, resources to be accessed, and the HTTP Version Used. Next is a header section, which describes additional information to be used by the server. After the header is a blank line, you can add any other data [called the body].

2. Difference Between get and post

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 send the connection address to the server, and the server obtains the information through the address parameters. Generally, these parameters are in plain text and can be seen in the browser address bar. While post is submitted to the server page through the input and other elements of the form, which is generally invisible.

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

 

The following is a simple example to illustrate their differences:

<! -Submit the form through get and Post respectively -->
<Form action = "getpost. asp" method = "get">
<Input type = "text" name = "text" value = "http://wxf0701.cnblogs.com //>
<Input type = "Submit" value = "Get mode"> </input>
</Form>
<Br>
<Form action = "getpost. asp" method = "Post">
<Input type = "text" name = "text" value = "http://wxf0701.cnblogs.com/>
<Input type = "Submit" value = "post mode"> </input>
</Form>
<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 by post is: "<B> <% = request. Form (" text ") %> </B>" <br>
<% End if %>

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.