In the web, the difference between the post and get Comments

In the web, the difference between the post and get Comments

Prior to distinguish get and post says, we should first understand what is HTTP.

HTTP Profile

HTTP is a simple request - response protocol is Hyper Text Transfer Acronym Protocol (Hypertext Transfer Protocol) is a protocol used to transfer data based on the TCP / IP communication protocol.

HTTP works

HTTP is based on Client / Server mode, connection-oriented, a stateless protocol. Browser as a client via HTTP to the HTTP server URL (ie WEB server) sends a request. HTTP typical process is as follows:
(1) establishing the client connection to the server
(2) the client request to the server
(3) the server accepts the request and return the results as a response according to the request
(4) the client disconnects from the server

HTTP Note:
HTTP connection-oriented : i.e. only one request per connection processing. After the server processes client requests and receives the customer's response, i.e., disconnected.
HTTP is an independent media : as long as the client and the server knows how to handle the content data, any type of data can be sent via HTTP. The client and server specify the appropriate MIME-type content type.
HTTP is stateless : no state is no protocol for transaction processing and memory. If the lack of state means that the subsequent processing required in front of the information, it must be retransmitted, which may result in the amount of data transmitted for each connection is increased. On the other hand, when it does not require previous information in response to a faster server.

The method of HTTP request

The OPTIONS : Returns the server for a particular resource request method supported by HTTP. May be transmitted to the Web server using the '*' to test the performance of the server requests
the HEAD : similar to the GET request, returns a response but not the specific content, for obtaining the header
GET : page information specified by the request, and return entities body
the POST : Submit data processing request to the specified resource (e.g., file submission form or upload). Data contained in the request body. POST requests may result in modifications to create and / or existing resources to new resource
PUT : upload the latest content from the server to the client
DELETE : delete the specified server requests a page
the TRACE : back to the requesting server receives considerably, mainly for testing diagnosis or
the cONNECT : the HTTP / 1.1 protocol can be reserved for connection to the pipeline mode proxy server

The difference between GET and POST

A,
GET request will be attached after the URL, in order? Segmentation URL and transmit data, a plurality of parameters & connect, have length restrictions.
Request body placed in the post request (content), there is no length limit.

Two,
GET request for information retrieval and should be safe and idempotent of. So get requests when the browser fallback is harmless.
post requests may modify resources on the server, so that do not meet safety and idempotent. And the browser will submit the request again rolled back.

Security means a non-modification information, that is, the operation for acquiring information not modify the information. In other words, GET requests should generally not cause side effects, that is, it is merely to obtain information resources, like database queries, it would not modify, add data, will not affect the resources of the state.
Idempotence (Idempotence) means that no matter how many times to call this URL, there will not be the result of different HTTP method. In the actual process, this provision is not so strict. For example, in a news application, news site's front page constantly updated, although the second request will return a different batch of news, this operation is still considered safe and idempotent, because it always returns the current news.

Three,
GET requests can be cached.
post request can not be cached.

Four,
GET request as it will appear in the URL, it is unsafe and can not be used to transmit sensitive information.
with respect to post requests get request, it is relatively safe. (But still be obtained by post capture request data to be transmitted)

Five,
GET request can only be url encoded.
post requests support a variety of encoding.

Here Insert Picture Description

Published 34 original articles · won praise 55 · views 9882

Guess you like

Origin blog.csdn.net/weixin_43996007/article/details/104432487