How does HTTP request get and post be implemented?

Source: Internet
Author: User
Tags html header

1. HTTP request Format:
<request line>
<blank line>
[<request-body>]
In an HTTP request, the first line must be a request line, which describes the type of request, the resources to be accessed, and the HTTP version used. This is followed by a header section that describes the additional information that the server will use. After the header is a blank line, then you can add any additional data [called the body].
2. Get vs. Post differences
HTTP defines different ways to interact with the server, and the most basic method is GET and POST. Http-get and http-post are standard protocol verbs that use HTTP to encode and transmit variable name/variable value pairs of parameters and to use the relevant request semantics. Each http-get and Http-post consists of a series of HTTP request headers that define what the client requests from the server, and the response consists of a series of HTTP reply headers and answer data, which returns an answer if the request succeeds.
Http-get pass parameters in the format of urlencoded text using MIME type application/x-www-form-urlencoded. Urlencoding is a character encoding that guarantees that the transmitted parameters consist of text that follows the specification, such as the encoding of a space as "%20". Additional parameters can also be considered as a query string.
Similar to Http-get, the Http-post parameter is also encoded by the URL. However, the variable name/variable value is not transmitted as part of the URL, but is placed inside the actual HTTP request message.
(1) Get gets data from the server and post is the data that is sent to the server.
On the client side, the Get method submits the data through the URL, the data is visible in the URL, and the data is placed within the HTML header by the Post method.
(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.
(3) The data submitted by the Get method can only have up to 1024 bytes, while post does not have this limit.
(4) 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.
Note: The so-called security means that the operation is used to obtain information rather than modify information. Idempotent means that multiple requests to the same URL should return the same result. The complete definition is not as strict as it seems. In other words, GET requests generally should not have side effects. Fundamentally, the goal is that when a user opens a link, she can be confident that the resource has 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 the POST request because the site is different after the annotation is submitted (for example, an annotation appears below the article).
Example
Here's a simple example to illustrate their differences:
<!-submit the form by Get and post respectively--
<form action= "getpost.asp" method= "Get" >
<input type= "text" name= "text" value= "Http://www.jb51.net" >
<input type= "Submit" value= "Get Mode" ></INPUT>
</FORM>
<BR>
<form action= "getpost.asp" method= "POST" >
<input type= "text" name= "text" value= "Http://www.jb51.net" >
<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%>

How does HTTP request get and post be implemented?

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.