The difference between post and get in HTML can be done by using the post. HTTP defines different methods of interacting with the server, and the most basic methods are 4 kinds, namely get,post,put,delete. URL full name is a resource descriptor, we can think of: a URL address, which is used to describe a network of resources, and HTTP get,post,put,delete corresponding to this resource to check, change, increase, delete 4 operations. Here, you should have a rough idea, get is generally used to obtain/query resource information, and post is generally used to update resource information. Detailed description, there are probably the following points:
1. Get is to obtain data from the server, post is to transfer data to the server.
2. Get is to add the parameter data queue to the URL of the action attribute that submits the form, and the value corresponds to each field one by one in the form, which can be seen in the URL. Post is the HTTP post mechanism that places the fields in the form and their contents in the HTML header to the URL address that the action attribute refers to. This process is not visible to the user.
3. For Get way, server end uses Request.QueryString to obtain variable value, for post way, server end uses Request.Form to obtain the submitted data.
4. The amount of data transferred by get is small and cannot be greater than 2KB. Post transfers have a large amount of data, which is generally default to unrestricted. In theory, however, the maximum number of IIS4 is 100KB in 80KB,IIS5.
5. Get security is very low, post security is high. But the execution efficiency is better than the Post method.
according to the HTTP specification, get is used for information acquisition, and should be secure and idempotent. Safetymeans that the action is used to get information rather than modify it. In other words, get requests should not generally have side effects. That is, it simply gets the resource information, like a database query, that does not modify, adds data, and does not affect the state of the resource.
* Note: The meaning of security here is simply to modify information.
Power etcmeans that multiple requests to the same URL should return the same result. Here, I'll explain the concept of idempotent:
Idempotent (idempotent, idempotence) is a mathematical or computational concept that is common in abstract algebra.
Idempotent has several definitions:
For monocular operations, if an operation is the same as the result of doing this operation for a number of times in a range, then we call the Operation Idempotent. For example, the absolute value operation is an example, in the real number concentration, has abs (a) =abs (ABS (a)).
For binocular operations, it requires that when the two values of the participating operation are equivalent, if the result of the operation is equal to the two values of the participating operation, it is said that the power of the operation, such as the function of the maximum of two numbers, has the power in the real number concentration, that is, max (x,x) = x.
After reading this explanation, you should be able to understand the meaning of get idempotent.
But in practical applications, the above 2 provisions are not so strict. Cite an example of someone else's article:
For example, the front pages of news sites are constantly being updated. Although the second request returns a different batch of news, the operation is still considered safe and idempotent, as it always returns the current news. Fundamentally, if the goal is when a user opens a link, he can be sure that from his point of view there is no change in resources.
according to the HTTP specification, post represents a request that might modify a resource on a variable serverContinue to take just that news website as an example, readers to the news to publish their own comments should be implemented by post, because the site after the comments submitted resources are different, or the resources have been modified.
problems that are often found in practical applicationsIt probably says some of the original reason questions about Get and post in the HTTP specification. But in practice, many people do not follow the HTTP specification, which causes many reasons for this problem, such as:
1. Many people are greedy for convenience, update the resource with GET, because the post must be to form (form), this will be a bit of trouble.
2. The increase of resources, delete, change, check operation, in fact, can be completed through the get/post, do not need to use put and delete.
3. Another is that the early web MVC framework designers did not consciously view and design URLs as abstract resources, so a more serious problem is that the traditional Web MVC framework basically supports only get and post two HTTP methods, The put and delete methods are not supported.
* Explain briefly MVC:MVC is originally in the desktop program, m refers to the data model, v refers to the user interface, 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 representations.
The above 3 points typically describe the old style (no strict adherence to the HTTP specification), and as the architecture progresses, there is now rest (representational state Transfer), a new style of support for HTTP specifications, not to mention here, refer to the RESTful Web Services. With the question of the original reason, let's look at the difference between get and post from the surface as above1.GET the requested data is appended to the URL (that is, the data is placed in the HTTP protocol header) to split the URL and transmit the data, and the parameters are connected by &, such as: login.action?name=hyddd&password= IDONTKNOW&VERIFY=%E4%BD%A0%E5%A5%BD. If the data is an English letter/number, 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 the xx in%xx for the symbol in the 16 in ASCII representation.
Post puts the submitted data in the package body of the HTTP package.
2. "Get way submitted data can only be 1024 bytes, theoretically post No limit, can pass a large number of data, IIS4 in the largest 80kb,iis5 in the 100KB" ...
The above sentence is from other articles I turn over, in fact, this is wrong, inaccurate:
(1). First of all, "the data submitted by Get method can only be 1024 bytes", because get is to submit data through the URL, then the amount of data to be submitted can be directly related to the length of the URL. In fact, the URL does not have the problem of the upper limit of the parameters, the HTTP protocol specification does not limit the length of the URL. This restriction is restricted by specific browsers and servers. The Internet Explorer limit for URL length is 2083 bytes (2k+35). For other browsers, such as Netscape, Firefox, etc., there is no theoretical length limit, the limit depends on the operating system support.
Note that this limit is the length of the entire URL, not just the length of your parameter value data. [See Resources 5]
(2). In theory, post is not the size limit, the HTTP protocol specification is not the size limit, said that "post data volume exists 80k/100k size limit" is inaccurate, post data is unrestricted, the limit is the processing of the server's processing capacity.
For ASP programs, the request object has a 100K data length limit when it processes each form field. But there is no such limit if you use Request.BinaryRead.
Extended by this, for IIS 6.0, Microsoft has increased its restrictions for security reasons. We also need to note:
1). The maximum number of IIS 6.0 default ASP post data is 200KB, and each form field limit is 100KB.
2). The maximum size of the IIS 6.0 default upload file is 4MB.
3). The default maximum request header for IIS 6.0 is 16KB.
IIS 6.0 does not have these restrictions before. [See Resources 5]
So the above 80k,100k may be just the default value (Note: I haven't confirmed the parameters about IIS4 and IIS5), but I'm sure I can set it myself. Because each version of IIS does not have the same default values for these parameters, refer to the relevant IIS configuration documentation.
3. In ASP, the server gets get request parameter with Request.QueryString, gets the POST request parameter with Request.Form. In the JSP, with Request.getparameter (\ "xxxx\") to get, although the JSP also has request.getquerystring () method, but the use of more trouble, such as: Pass a test.jsp?name= HYDDD&PASSWORD=HYDDD, with Request.getquerystring () is: name=hyddd&password=hyddd. In PHP, the data in get and post can be obtained separately with $_get and $_post, while $_request gets the data from the get and post two requests. It is noteworthy that the use of the JSP in the request and PHP use of $_request will have hidden dangers, this next time to write a summary of the article.
4.POST security is higher than get security. Note: The security described here is not the same concept as the "security" mentioned above. The meaning of the above "security" is simply not to make data modifications, and here the meaning of security is the meaning of the real, for example: to submit data through get, user name and password will be clear on the URL, because (1) login page is likely to be cached by the browser, (2) Other people to view the history of the browser, Then others can get your account number and password, in addition, use get submit data may also cause Cross-site request forgery attack.
To sum up, get is a request to send data to the server, and post is a request to submit data to the server, in form (form), method defaults to "get", in essence, get and post only send mechanism is different, not one to take a hair.
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.