The difference between HTTP get and post

Time:2019-12-1

1. HTTP request format:
<request line>
<headers>
<blank line>
[<request-body>]

In an HTTP request, the first line must be a request line that 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 first part is a blank row, after which any other data [called body] can be added.

2. Difference between get and post

HTTP defines different ways to interact with the server. The most basic methods are get and post. Http-get and http-post are standard protocol verbs using HTTP, which are used to code and transmit variable name / variable value pair parameters, and use related request semantics. Each http-get and http-post consists of a series of HTTP request headers, which define what the client requests from the server, and the response consists of a series of HTTP response headers and response data. If the request is successful, the response is returned.
Http-get passes parameters in the form of urlencoded text using MIME type application / x-www-form-urlencoded. Urlencoding is a character encoding to ensure that the parameters to be transmitted are composed of text that follows the specification. For example, the encoding of a space is% 20. Additional parameters can also be considered a query string.
Similar to http-get, http-post parameters are also URL encoded. However, the variable name / value is not delivered as part of the URL, but is delivered inside the actual HTTP request message.

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

On the client side, get mode submits data through URL, and data can be seen in the URL; post mode submits data in HTML header.

(2) for the get method, the server uses request.querystring to get the value of the variable. For the post method, the server uses request.form to get the submitted data.

(3) the data submitted by get mode can only have 1024 bytes at most, while post does not have this limit.

(4) safety issues. As mentioned in (1), when using get, the parameters are displayed on the address bar, while post does not. Therefore, if the data is Chinese data and non sensitive data, then use get; if the data entered by the user is not Chinese characters 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 it. Idempotent means that multiple requests for the same URL should return the same result. The full definition is not as strict as it seems. In other words, get requests should generally have no side effects. Basically, the goal is that when a user opens a link, she can be sure that the resource hasn’t changed from her point of view. For example, the front page of a news site is constantly updated. Although the second request will return a different batch of news, the operation is still considered safe and idempotent because it always returns the current news. vice versa. Post requests are not so easy. Post indicates a request that may change resources on the server. Still take the news site as an example. Readers’ comments on the article should be implemented through post request, because the site is different after the comments are submitted (for example, an annotation appears below the article).

Example;

Here 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=”//www.jb51.net”>
< input type = “submit” value = “get method” >
</FORM>
<BR>
<FORM ACTION=”getpost.asp” METHOD=”post”>
<INPUT TYPE=”text” NAME=”Text” VALUE=”//www.jb51.net”>
< input type = “submit” value = “post method” >
</FORM>
<BR>

<% If Request.QueryString(“Text”) <> “” Then %>
The string passed through get is: “< b > < request. Querystring (” text “)% > < b >” < br >
<% End If %>

<% If Request.Form(“Text”) <> “” Then %>
The string passed through post is: “< b > < request. Form (” text “)% > < b >” < br >
<% End If %>