Differences between http get/POST requests

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 is a request line. In other words, the request method, the resource to be accessed, and the HTTP Version. The header in the first section describes the additional information to be used by the server. The header is followed by a blank line and then the request body.
2. Get and post
HTTP defines different methods for interaction with the server. The most basic methods are post and get. HTTP-GET and HTTP-POST are standard protocol verbs that use HTTP to encode and transmit variable name/variable value pair parameters and return a response if the request succeeds. If the URL string contains Chinese characters, base64 is used for encryption.

In post mode, the variable name/variable value is not transmitted as part of the URL, but is transmitted inside the actual HTTP request message.

The default get method is used for browser requests.
Get is used to obtain/query resource information, while post is used to update resource information.
# According to HTTP specifications, get is used for information retrieval, and should be secure and idempotent.
1. The so-called security means that this operation is used to obtain information rather than modify information. In other words, get requests generally do not have side effects. That is to say, it only obtains the resource information, just like the database query. It does not modify, add data, and does not affect the resource status.

* Note: security only indicates that the information is not modified.

2. idempotence means that multiple requests to the same URL should return the same result.

# According to HTTP specifications, post indicates a request that may modify resources on the server.

| GET | post |
| ----------------------------------------------------- + --------------------------------------------------------- |
| Get data from the server | send data to the server |
| Submit data through URL on the client | put the data in the HTML header for submission |
| The server uses request. querystring to obtain the variable value | the server uses request. Form to obtain the submitted data |
| The submitted data is restricted by the URL length. For example, the length of IE is 2083 bytes. | no |
| The parameter is displayed in the address bar, which is insecure | secure |

 

ExampleCode
# + Begin_example
<! -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 %>

* Http response instance *

HTTP Response instance

HTTP/1.1 200 OK
Date: sat, 31 Dec 2005 23:59:59 GMT
Content-Type: text/html; charset = ISO-8859-1
Content-Length: 122
<HTML>
<Head>
<Title> wrox homepage </title>
</Head>
<Body>
<! -- Body goes here -->
</Body>
</Html>
2. The most common status codes are:

◆ 200 (OK): The resource is found and everything is normal.
◆ 304 (not modified): The resource has not been modified since the last request. This is usually used for browser caching.
◆ 401 (unauthorized): the client has no permission to access this resource. This usually requires the user to enter the user name and password in the browser to log on to the server.
◆ 403 (Forbidden): the client is not authorized. This is usually because an incorrect user name or password is entered after 401.
◆ 404 (not found): the requested resource does not exist at the specified position.

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.