Get and post in HTTP

Source: Internet
Author: User
Tags html header

The get method and post method in HTTP protocol are different. The original text in rfc1945 is as follows:

8.1 get

The get method means retrieve whatever information (in the form of
Entity) is identified by the request-Uri. If the request-Uri refers
To a data-producing process, it is the produced data which shall be
Returned as the entity in the response and not the source text of
Process, unless that text happens to be the output of the process.

The semantics of the get method changes to a "Conditional get" if
Request Message received des an IF-modified-since header field.
Conditional get method requests that the identified resource be
Transferred only if it has been modified since the date given by
If-modified-Since Header, as described in section 10.9.
Conditional get method is intended to reduce network usage
Allowing cached entities to be refreshed without requiring multiple
Requests or transferring unnecessary data.

8.3 Post

The post method is used to request that the destination Server Accept
The entity enclosed in the request as a new subordinate of
Resource identified by the request-URI in the request-line. Post is
Designed to allow a uniform method to cover the following functions:

O annotation of existing resources;

O posting a message to a bulletin board, newsgroup, mailing list,
Or similar group of articles;

O Providing a block of data, such as the result of submitting
Form [3], to a data-handling process;

O extending a database through an append operation.

The actual function was med by the post method is determined by
Server and is usually dependent on the request-Uri. The posted entity
Is subordinate to that URI in the same way that a file is subordinate
To a directory containing it, a news article is subordinate to
Newsgroup to which it is posted, or a record is subordinate to
Database.

A successful post does not require that the entity be created as
Resource on the origin server or made accessible for future
Reference. That is, the action was med by the post method might not
Result In a resource that can be identified by a URI. In this case,
Either 200 (OK) or 204 (NO content) is the appropriate response
Status, depending on whether or not the response provided des an entity
That describes the result.

If a resource has been created on the origin server, the response
Shocould be 201 (created) and contain an entity (preferably of Type
"Text/html") which describes the status of the request and refers
The new resource.

A valid Content-Length is required on all HTTP/1.0 POST requests.
HTTP/1.0 server shocould respond with a 400 (Bad request) message if it
Cannot determine the length of the Request Message's content.

Applications must not cache responses to a POST request because
Application has no way of knowing that the server wocould return
Equivalent response on some future request.

 

Translated into Chinese (Huang Xiaodong translation, xdhuang@eyou.com) is

8.1 get

The get method is to obtain the information of the resource specified by the request URI in Entity mode. If the request URI is only one
Data generation process, the results returned in the response object are directed by the results of the processing process.
Instead of returning the descriptive text of the processing process, unless that text is exactly the output of the processing.
If the request message contains the IF-modified-since header field, the get method syntax is changed to "condition get ",
That is, "(conditional get )". The conditional get method can be used to determine the specified resource.
If-modified-since
Otherwise, the data is not transmitted. This condition "get" allows cached entities without having to go through multiple requests or unnecessary
Data transmission can be refreshed to help reduce network load.

8.3 Post

The post method is used to send a request to the target server, asking it to accept the object attached to the request and
Used as an additional sub-item of the resource specified by the request URI in the Request queue (request-line. Post Design
To achieve the following functions in a unified way:

O annotation of existing resources );

O send messages to bulletin boards, newsgroups, email lists, or similar discussion groups;

O submit data blocks. For example, submit the results of a form (Form [3]) to the data processing process;

O expand the database through additional operations.

The actual function of the post method is determined by the server and usually depends on the request URI. In the post process,
The object is the subordinate part of the URI, as if the file belongs to the directory containing it, And the newsgroup file belongs to the issued
The newsgroups and records of this file are the same as those of their databases.

A successful post does not need to create an object on the original server and use it as a resource.
Access conditions. That is to say, the POST method may not necessarily point to the resource specified by the URI. In this case,
200 (successful) or 204 (NO content) are appropriate response states, depending on the actual response entity to complete
Description.

If a resource is created on the original server, the response should be 201 (created) and contain an entity
(Most suitable for the "text/html" type), which records the status description of the new resource request.

The valid Content Length (Content-Length) must be specified in all HTTP/1.0 POST requests ).
If the length of the HTTP/1.0 server cannot be determined when it receives the request message, it will return 400 (not
Method Request) code.

Applications cannot cache responses to post requests, because as applications, they cannot know
How will the server respond to future requests.

Summary and explanation:

I. The post and get methods are at least two different in use:

  1. The get method transmits user input through URL requests. That is, add the parameter data queue to the URL referred to by the Action attribute of the submission form. The values correspond to each field in the form one by one and can be seen in the URL. Post uses the http post mechanism to place fields in the form and their content in the HTML header and send them to the URL address referred to by the Action attribute. You cannot see this process.
  2. You must use request. querystring to obtain the value of a variable for get-based submission. When you submit a get-based submission, you must use request. Form to access the submitted content.

Prompt

Submitting data through the get method may cause security issues. For example, a login page. When you submit data using the get method, the user name and password will appear on the URL. If:

    • The login page can be cached by the browser;
    • Others can access the customer's machine.

Then, others can read the customer's account and password from the browser's history. Therefore, in some cases, the get method may cause serious security problems.

Suggestion: In form, the POST method is recommended.

2. <form action = "" method = "Post"> A prompt box is displayed during refresh, asking whether to resend the request. If it is changed to method = "get", this prompt is not displayed; the post request has no length limit (at least theoretically), and the GET request has a length limit, which cannot exceed 2048 bytes.

 

Note: The content of "summary and explanation" is obtained from the Internet.

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.