The difference understanding between get method and post in HTTP protocol

Source: Internet
Author: User
Tags html header

The difference between 1.get and post

(1) URL length
The length of get is only 2k, if the data is too long, it is easy to lose data. (Get must be an ASCII character)
And the post is unrestricted, so it can be beautiful, such as the address of the blog, if the address is very long, it does not look beautiful, (post supports the entire ISO10646 character set)


(2) Security
The request value for get is reflected on the URL.
The post is not, the data placed in the HTML header submitted, not to allow the client to see, but also relatively safe

(3) When the Web page is refreshed, is it obsolete
Get method requests when the page is refreshed, if it is out of date, the page is obsolete and the data will be retransmitted.
When the Post method is refreshed in the Web page, if it is obsolete, the page is obsolete and the data is retransmitted.

An easily misunderstood word:
Get is a request to send data to the server, passing parameters in the format of the MIME type application/x-www-form-urlencoded urlencoded text
and post is a request to submit data to the server,
In form (form), method defaults to "get", in essence, get and post are only different sending mechanisms, not a single hair.


What to do:
(1) So, if the data is Chinese and is not sensitive data, then use get;
If the user enters data that is not a Chinese character and contains sensitive data, use post as a good
If you want to make a request for a form (register and log in), you should use post
(2) PHP method: POST can be used $http_post_value[],get with $http_get_value[] to get the value, also can be $_get and $_post method
asp: For Get methods, the server end uses Request.QueryString to obtain the value of the variable.
For post methods, the server side uses Request.Form to obtain the submitted data.


Extended Knowledge Point: HTTP protocol

 get/css/news070130.css http/1.1
 accept: */*
 referer:http://news.qq.com/a.htm
 ACCEPT-LANGUAGE:ZH-CN
 accept-encoding:gzip, deflate
 if-modified-since:thu, Mar 2007 02:05:43 GMT; length=11339
 user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1. NET CLR 1.1.4322;. NET CLR 2.0.50727)
 host:news.qq.com
 connection:keep-alive
 cookie : Ssid=idlsesels; flv=9.0; ICACHE=ADLFMBGC; Adid=adsdifids; isflucky_50829637=0;
       //Note: A blank line under the statement "Connection:keep-alive" is required.

The

Explains that the browser uses the Get method to request document/index.html. Browsers allow only plaintext text files and HTML text files to be received, and the engine used is mozilla/4.5 (Netscape).
 
 POST/Login.php  http/1.1
 accept:image/gif,*/*
 ACCEPT-LANGUAGE:ZH-CN
 accept-encodeing:gzip
 user-agent:msie6.0
 host:www.some.com
 connection: Keep-alive
 content-length:7
 cache-control:no-cache
 Cookie:name1=value1; name2=value2 ;


  Description:
  get: Requests the specified page information and returns the entity body.
  Head: Only the header of the page is requested.
  POST: Requests the server to accept the specified document as a new subordinate entity for the identified URI.
  Put: Replaces the contents of the specified document with data that is transferred from the client to the server.
  Delete: Requests the server to delete the specified page.
  OPTIONS: Allows clients to view server performance.
  TRACE: Requests the server to return the resulting content in the entity body part of the response.
  PATCH: An entity contains a table that describes the difference between the original content represented by that URI.
  MOVE: Requests the server to shift the specified page to another network address.
  Copy: Requests the server to copy the specified page to another network address.
  Link: Request a server to establish a link relationship.
  UNLINK: Unlink relationships.
  Wrapped: Allows clients to send packaged requests.
  Extension-mothed: Additional methods can be added without altering the agreement.

  user-agent: Browser information for the client. The
  connection:close indicates that a short connection is used, and keep-alive indicates that the client supports persistent connections.
  date: The current time that the message was generated.
  accept-language: The language supported by the client.
  cache-control: Whether the client supports Cache. No-cache indicates that the client does not support cache, such as max-age=3600, to tell the user Agent how long the response result of the request is valid, within the validity period, when the user again needs access, directly from the client local extraction, do not need access to the server. The
  referer:referer is used to tell the server which URL the request originated from, and it can be used to track the user's Web Access path.
  if-modified-since: If the request message contains a If-modified-since header field, the syntax of the Get method becomes "condition got", that is, "(conditional get)." The conditional get method can determine the specified resource, and if it has been updated after the specified date in the If-modified-since header field, the transmission will not start, otherwise it will not be transmitted. This condition get allows the cached entity to be refreshed without having to go through multiple requests or unnecessary data transfers, thereby helping to reduce network load.
  last-modified:sun, Dec 2008 23:52:56 GMT
  etag: 1cbf3-dfd-3a2adcd8″
     general application in the file download, to identify the response content of the last modification time or content than the code, the next time the user agent needs, the service first determines whether the two values are consistent with the server, the same does not need to return content.
  expires: The response of the request expires at what time, and the agent can return the previous response results directly from the cache before it is invalidated.
  host: Specifies the host and port number on which the resource is requested. The http/1.1 request must specify host or the server will return a 400 status code.

  When the server responds, the information for its status line is an HTTP version number, a status code, and a simple explanation of the status code. The 5-class status code is listed in detail:
 ① Client Error
  100 continue
  101 Exchange Protocol
 ② Success
  OK
  201 Created
  202 receive
  203 non-authenticated information
  204 NOTHING
  205 Reset content
  206 part
 ③ REDIRECT
  300 multi-way selection
  301 Permanent transfer
  302 temporary transfer
  303 See other
  304 unmodified (not Modified)
&nbs  P 305 using the proxy
 ④ client error
  400 error request (Bad Request)
  401 not certified
  402 need to pay
  403 Forbidden (F  Orbidden)
  404 Not Found (not Found)
  405 method does not allow
  406 not accept
  407 requires proxy authentication
  408  Request Timeout
  409 conflict
  410 failure
  411 required length
  412 failed
  413 request entity too large
  414  Request URI is too long
  415 does not support media type
 ⑤ server error
  500 server Internal Error
  501 Not implemented (not implemented)
  502 Gateway Failure
  504 Gateway Timeout
  505 HTTP version does not support

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.