The "Get" method should the used when the form is idempotent---two orthogonal concepts---

Source: Internet
Author: User
Tags rfc

https://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.1

17.13.1Form Submission Method

The method attribute of the FORM element specifies the HTTP method used to send the form to the processing agent. This attribute could take the values:

    • get:With the HTTP "get" method, the form data set are appended to the URI of specified by the action attribute (with a Question-mar K ("?") as separator) and this new URI are sent to the processing agent.
    • post:With the HTTP ' post ' method, the form data set is included in the body of the form and sent to the processing agent.

The "Get" method should was used when the form is idempotent (i.e., causes no side-effects). Many database searches has no visible side-effects and make ideal applications for the "get" method.

If the service associated with the processing of a form causes side effects (for example, if the form modifies a database or subscription to a service), the "post" method should is used.

Note. The "Get" method restricts form data set values to ASCII characters. Only the ' post ' method (with enctype = ' Multipart/form-data ') is specified to cover the entire [ISO10646] character set.

Http://www.cnblogs.com/nankezhishi/archive/2012/06/09/getandpost.html

"

What is the difference between get and post? And why most of the answers on the internet are wrong.

If someone asks you,get and post, what's the difference? How would you respond?

My experience.

I was asked this question a few days ago. I say get is used to get data, POST, which is generally used to send data to the server.

The answer seems not to be what he wants. So he went on asking if there was any other difference? I say it's just a name, and if the server supports it, he can change the get to a name called GET2. He asked, is that the simple name of the difference? I think, I think if the specific difference, can only go to the RFC document, but also depends on the server (referred to as Apache, IIS) Implementation . But I have to admit, I did not look closely at the RFC documentation for HTTP. So I said, I'm not familiar with the HTTP protocol. This is the end of the question.

The most common answer

After coming back and thinking for a long time, what was he trying to ask me? I've always felt that get and post have nothing to do with anything other than semantics, since I started learning about Web programming.

Probably a lot of people have guessed that the answer he wants is:

1. Get uses URL or cookie to pass the parameter. And the post puts the data in the body.

2. Get URLs are limited in length, then the post data can be very large.

3. Post is safer than get because the data is not visible on the address bar.

Unfortunately, these distinctions are all wrong, and, unfortunately, the answer is the headline of Google search, but I don't think they are the answer, because in my opinion they are all wrong. Let me explain to you in one by one.

Get and post are not related to how data is passed

Get and post are defined by the HTTP protocol. In the HTTP protocol, method and data (URL, Body, Header) are two orthogonal concepts, that is, there is no correlation between the method used and how the application layer's data is transmitted .

HTTP is not required, if the method is the post data will be placed in the body. There is no requirement that if the method is get, the data (parameters) must be placed in the URL instead of being placed in the body.

So, where does the idea of the internet spread widely? I found a similar description in the HTML standard. This is consistent with the online spread of the statement. However, this is only a convention for the use of the HTTP protocol by the HTML standard. How can it be the difference between get and post?

Also, modern Web servers support requests that contain the body in get. Although this request may not be issued from the browser, but now the Web server is not only for the browser, has completely exceeded the scope of the HTML server.

What's the use of knowing this? I don't want to explain, sometimes I have to hurt myself to remember to live.

The HTTP protocol has no limit on the length of both get and post

The HTTP protocol explicitly states that neither the HTTP header nor the body has a length requirement. There are two reasons for the limitation of URL length:

1. Browser. It is said that the early browser will limit the length of the URL. It is said that IE will limit the length of the URL to 2048 characters characters (spread very wide, and many colleagues agree). But I tried it myself, and I constructed a 90K URL to access live.com through IE9, which is normal. Things on the internet, even on Wikipedia, can't be trusted.

2. Server. The URL is long and is a burden on server processing. There is not much data for a session, and now if someone maliciously constructs a few m-sized URLs and keeps accessing your server. The maximum number of concurrent servers will obviously drop. Another way to attack is to tell the server content-length is a very large number, and then only to the server to send a little data, hey, the server you are silly to wait to go. Even if you have a timeout setting, this deliberate secondary access timeout can also make the server suffer. In view of this, most servers for security, stability considerations, the URL length will be added restrictions. However, this restriction is for all HTTP requests and is not related to get or post.

Security insecure and get, post does not matter

I think this is really Chinese characteristics. I'll tell you a little joke, and everyone should be able to understand how ridiculous this is.

People who feel that post data is safer than get data will say

"Anti-gentleman is not a villain; China small white more, can prevent small white users on the line." ”

"Hum," I do not think,"then you do not say,URL parameters are encode , or Base64 , small white also can not understand AH." "

The man retorted,"Encode is too simple, smart little white can easily be decode and modified." "

I laughed,"kettle black Ear, and then the clever little white will also cut the packet and re-hair,Opera has this function." "

The man sinister sacrificed the artifact--the power of final interpretation , said,"This is not a small white." "

My day.

The last bit of feeling

I've been a Windows desktop app before, and I didn't know much about web development until I turned to server-side development more than a year ago to start contacting HTTP. (Note that I'm talking about HTTP, not HTML.) The server Open interface is designed based on the rest concept, and the protocol used is HTTP, but the content being transmitted is not HTML. This is not a Web Server, but a web Service)

So my understanding of get and post is purely rooted in the HTTP protocol. They only have a bit of a fundamental difference, simply say, one for getting data, one for modifying data. Please refer to the RFC documentation for details.

If a person in the beginning to do web development, it is likely to use HTML to the HTTP protocol, as the HTTP protocol is the only reasonable use of the way. Thus made a sweeping mistake.

Maybe someone will think I'm in a dead alley. I just do not like ambiguous, do not like the border is unclear, the concept is not clear, do not like "take doctrine", also do not like to be other like the person who likes to ridicule the shame.

"Knowing is known, I do not know it, and I know it." ”

"

The "Get" method should the used when the form is idempotent---two orthogonal concepts---

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.