HTTP request Method GET POST "Summary"

Source: Internet
Author: User

An overview of HTTP 8 Request methods The http/1.1 protocol defines eight methods (sometimes called "actions"), respectively:Get,post,put, Options,head,delete,trace,connectTo indicate the different ways of operating the resources specified by Request-uri, as described below:
  1. OPTIONS: Returns the HTTP request method that the server supports for a particular resource, or a request to send a ' * ' to the Web server to test the functionality of the server.
  2. HEAD: Ask the server for a response that is consistent with the GET request , except that the response body will not be returned . This method allows you to obtain meta information contained in the response message header without having to transmit the entire response content .
  3. GET: "Check" makes a request to a specific resource.
  4. POST: "Change" submits data to the specified resource for processing requests (such as submitting a form or uploading a file). The data is included in the request body. A POST request may result in the creation of new resources and/or modification of existing resources.
  5. PUT: "Add" uploads its latest content to the specified resource location. if the URI does not exist, the server is asked to create the resource on request, and if so, the server accepts the requested content and modifies the original version of the URI.
  6. Delete: "Delete" requests the server to delete the resource identified by Request-uri.
  7. TRACE: echo the request received by the server, primarily for testing or diagnostics.
  8. The connect:http/1.1 protocol is reserved for proxy servers that can change connections to pipelines. Convert the request connection to a transparent TCP/IP channel.

The most basic methods of the above methods are 4 kinds, namely get,post,put,delete. URIUsed to describe a resource on a network, and the Get,post,put,delete in HTTP corresponds to the "check, change, increase, delete" of this resource 4 operations.
However, we use only get and post in the actual application,Other request methods can be indirectly implemented in these two ways。

Get request and POST request GET request
  • Generally speaking a GET request is used to obtain information, it only gets resources, and does not make changes to the resource without affecting the state of the resource .
  • A GET request is typically appended to a URL in the form of a query string. If the data is an English letter/number, it is sent as is, if it is a space, converted to +, if it is Chinese/other characters, the string is directly encrypted with BASE64, such as:%E4%BD%A0%E5%A5%BD, where xx in%xx is the symbol in 16 binary notation ASCII. Therefore, there is a certain security risk
  • There is a size limit to the data submitted by get, because get commits data through a URL, so the amount of data that get can commit is directly related to the length of the URL. In fact, the URL does not have the upper limit of the argument, theHTTP protocol specification does not limit the length of the URL. This restriction is restricted to specific browsers and servers . ie, for example, the URL length limit is 2083 bytes (2k+35). This point believes that many people have always thought that it is the 2k limit, in fact, it is not ah.

POST request
    • according to the HTTP specification, A POST request is a request that may modify resources on the server .
    • Post is to put the data in the form in the data body of the form, the parameter value pairs are sent through the request body to the server, post all the operation is not visible to the user.
    • There is no limit to post in theory, a large amount of data can be transmitted

Interview question: difference between GET request and POST request for GET request and POST request
  • The fundamental difference: get is used to get data, no changes are made to the data, and post is used to modify the data . changes are made to the data .
  • Get use URL to send parameters, the data is placed in the URL , is visible in the browser, very insecure;And post is the data placed in theRequest BodyIn, the user is not visible, relatively safe.
  • Get passes the data in the URL, although the HTTP protocol specification does not limit the length of the URL, but due to browser and server restrictions, so the URL of get will have a length limit, and post can send the data is not a length limit.

A table summarized on the W3school

GET POST
Back button/Refresh Harmless The data is resubmitted (the browser should tell the user that the data will be resubmitted).
Bookmark Bookmark can be bookmarked Bookmark not available for collection
Cache can be cached Cannot be cached
encoding type application/x-www-form-urlencoded application/x-www-form-urlencoded or Multipart/form-data. Use multiple encodings for binary data.
History The parameters remain in the browser history. Parameters are not saved in the browser history.
Limits on the length of data Yes. When data is sent, the Get method adds data to the URL, and the maximum length of the URL is 2K characters. Unlimited.
Restrictions on data types only ASCII characters are allowed. There is no limit. Binary data is also allowed.
security

GET is less secure than POST because the data sent is part of the URL.

Never use GET when sending passwords or other sensitive information!

post is safer than GET , Because parameters are not saved in the browser history or Web server logs.
Visibility of The data is visible to everyone in the URL. The data is not displayed in the URL.
2017-10-15

From for notes (Wiz)

HTTP request Method GET POST "Summary"

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.