Http defines different methods for interaction with the server. There are four basic methods: GET, POST, PUT, and DELETE. The full name of a URL is a resource descriptor. We can think that a URL address is used to describe resources on a network, while GET, POST, PUT, DELETE corresponds to the query, modify, add, and DELETE operations on this resource. Here, you should have a rough understanding. GET is generally used to obtain/query resource information, while POST is generally used to update resource information.
Http definesServer InteractionMethods, except for the GET method that we usually use most, there are actually PUT and DELETE methods for POST.
AccordingRFC2616The standard (the current HTTP/1.1) actually hasOPTIONS,GET,HEAD,POST,PUT,DELETE,TRACE,CONNECT
Let's simply end it.
1According to the HTTP specification, GET is used for information retrieval, and should be secure and idempotent.
(1). The so-called security means that the 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. Here I will explain it again.IdempotenceThis concept:Idempotence(Idempotent, idempotence) is a mathematical or computer concept, common in abstract algebra.
After reading the above explanation, you should be able to understand the meaning of the get power.
However, in practice, the above two rules are not so strict. Example of referencing others' articles: for example, the front pages of news sites are 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. Basically, if the target is to open a link, the user can be sure that the resource is not changed from his own perspective.
2According to the HTTP specification, post indicates a request that may modify the resources on the server. Continue to reference the above example: for news websites, readers should post their comments on news, because the Site Resources are different after the comments are submitted, or the resource is modified.
The above describes some of the principles of get and post in the HTTP specification. However, in practice, many people fail to follow the HTTP specification, which leads to many reasons, such:
1. A lot of people are greedy and convenient. Get is used to update resources, because form must be used for post, which will be a little troublesome.
2. You can add, delete, modify, and query resources through get/post without using put or delete.
3. In addition, early web MVC Framework designers did not consciously treat and design URLs as abstract resources, therefore, a serious problem is that the traditional Web MVC framework basically only supports the get and post HTTP methods, rather than the put and delete methods.
* MVC: MVC originally exists in the Desktop program, M is the exponential data model, V is the user interface, and C is the controller. The purpose of using MVC is to separate the implementation code of M and V, so that the same program can use different expressions.
The above three points are a typical description of the old style (not strictly compliant with HTTP specifications). With the development of the architecture, there is now a Representational State Transfer and a new style that supports HTTP specifications, for more information, see RESTful Web Services.
After talking about the principle, let's look at the difference between GET and POST on the surface:
1The data in the. GET request will be appended to the URL (that is, the data will be placed in the HTTP header? Splits the URL and transmits data. parameters are connected with each other, for example, login. action? Name = hyddd & password = idontknow & verify = % E4 % BD % A0 % E5 % A5 % BD. If the data is an English letter/number, it is sent as is. If it is a space, it is converted to +. If it is a Chinese character/other character, it is directly encrypted with BASE64, and the result is as follows: % E4 % BD % A0 % E5 % A5 % BD, where XX in % XX represents the ASCII represented in hexadecimal notation.
POST places the submitted data in the packet body of the HTTP package.
2. "The data submitted in GET mode can only be 1024 bytes at most. Theoretically, there is no limit on POST. A large amount of data can be transferred. The maximum size of IIS4 is 80 KB, and that of IIS5 is KB "??!
The above sentence was transferred from other articles. In fact, it is wrong and inaccurate:
(1 ). first, "the data submitted in GET mode can only be 1024 bytes". Because GET submits data through a URL, the amount of data that can be submitted by GET is directly related to the URL length. In fact, the URL does not have a parameter ceiling. The HTTP protocol does not limit the URL length. This restriction is imposed by specific browsers and servers. The length of the URL is limited to 2083 bytes (2 K + 35) by IE ). For other browsers, such as Netscape and FireFox, there is no length limit theoretically. The limit depends on the support of the operating system.
Note that this limit is the length of the entire URL, not just the length of your parameter value. [See References 5]
(2 ). theoretically, there is no size limit on POST and no size limit on HTTP specifications. it is inaccurate to say that "the size of POST data is limited to 80 K/K, there is no limit on POST data, and the restriction is the processing capability of the server's processing program.
For ASP programs, there is a K data length limit when the Request object processes each form field. However, if Request. BinaryRead is used, there is no such restriction.
With this extension, Microsoft has increased its restrictions for IIS 6.0 for security reasons. Note:
1). By default, IIS 6.0 has a maximum asp post data volume of KB, and each form field is limited to kb.
2). By default, IIS 6.0 uploads a file up to 4 MB.
3). By default, the maximum request header of IIS 6.0 is 16 kb.
These restrictions are not available before IIS 6.0. [See References 5]
Therefore, the 80 K and K values above may only be the default values (Note: I have not confirmed the IIS4 and IIS5 parameters), but they must be set by myself. Because the default values of these parameters are different for IIS in each version, refer to the relevant IIS configuration documents for details.
3In ASP, the server uses Request. QueryString to obtain the GET Request Parameters and Request. Form to obtain the POST Request parameters. In JSP, request. getParameter (\ "XXXX \"), although the jsp also has a request. the getQueryString () method is difficult to use, for example, passing a test. jsp? Name = hyddd & password = hyddd. What you get with request. getQueryString () is: name = hyddd & password = hyddd. In PHP, you can use $ _ GET and $ _ POST to obtain data in GET and POST respectively, while $ _ REQUEST can obtain data in GET and POST requests. It is worth noting that using $ _ request in REQUEST and PHP in JSP poses a risk. Next time I will write a summary article.
4. POST is more secure than GET. Note: The security mentioned here is not the same as the "Security" mentioned in GET. The above "Security" only means not to modify data, but here Security means the meaning of true Security. For example, if you submit data through GET, the user name and password will appear in the URL in plain text, because (1) the login page may be cached by the browser, (2) if others view the browser's historical records, they will be able to get your account and password. In addition, using GET to submit data may also result in Cross-site
Request forgery attack.
To sum up, Get is a request to request data from the server, while Post is a request to submit data to the server. In FORM, the default Method is "GET". In essence, GET and POST are only different sending mechanisms, not a single sending!
5,PUT: Send messages in the message body to a URL, which is similar to POST, but not commonly used.
Simply put: Usually used to send requests to the server. IfURI does not exist, The server is required according to the requestCreate Resources, IfExistThe serverAccept the request content and modify the original version of the URI Resource.
----- PUT requests are entities encapsulated in Request-URI. If Request-URI references an existing resource, the encapsulated object should be used as a modified version on the original server. If the Request-URI does not point to an existing resource and can be defined as a new resource by the requested user code, the original server can use this URI to create a new resource. If a new resource is Created, the original server must send a 201 (Created) Response to notify the user proxy. If the existing resource is modified, a 200 or 204 response is sent, indicating that the request is successfully completed. If the Request-URI is neither created nor modified, an appropriate error response should be given to reflect the nature of the problem. The entity recipient cannot ignore any Content-* (such as Content-Range) headers that are not understood or implemented, and must return a 501 response.
If the Request is cached and the Request-URI identifies one or more objects currently cached, the objects are deemed to have expired. The response of this method is not cached.
6. POST and PUT requestsFundamental differences
The uri of the post request indicates processing.The resource of the closed entity. The resource may be a data receiving process, a gateway of a protocol, or an independent entity that receives annotations.. However, the URI in the PUT request indicates thatClosed entity-the user agent knows the URI targetAndThe server cannot apply the request to other resources.. If the server wants the request to be applied to another URI, it must send a 301 response. The user agent can determine whether to forward the request through its own judgment.
No PUT is defined for HTTP/1.1.How does a request affect the status of the original server?.
The PUT request must beCompliance with information transmission requirements.
Unless otherwise stated, the object header in the PUT requestIt should be used for resources created or modified by PUT..