views:

717

answers:

8

The question title says it all.

Now, I know a difference between parameters in a URL and a POST parameter: some browsers may misbehave if the URL is too long, so it is not a good idea to stuff hundreds of parameters in a URL, even if your app can respond to a GET request.

For the sake of discussion, let's suppose the following web application: a user can input a series of (possibly hundreds of) X,Y coordinates. The server plots them in a chart, which is returned as an image.

This is clearly an example of an idempotent operation, so, according to the HTTP spec, it is recommended to be implemented as a GET operation. However, you can't build a URL with all the parameters, as it will be too long. Can a <form method="get"> handle that much parameters ?

I've also heard that <form method="get"> is completely equivalent to placing parameters in a URL ? Now, is that true for some browsers or for the whole HTTP protocol ? Is there a maximum length to a request ?

+2  A: 

What your browser actually does is build a really long url from the form inputs. Therefore there will be no difference between a URL and form Method="GET". Either one will result in the same URL being loaded.

Kibbee
+7  A: 

The HTTP spec does not set limitations, but the browsers and servers do. See here for specifics.

The browser will create a long URL if the method is set to GET for a form, so the above limitations apply.

Sunny
+1  A: 

I've also heard that <form method="get"> is completely equivalent to placing parameters in a URL ?

That's true, here is the corresponding RFC section

Is there a maximum length to a request ?

The spec says "The HTTP protocol does not place any a priori limit on the length of a URI."

However internet explorer 6 has a limit of 2,083 characters. Other browsers allow more characters but if you go that route you will basically have to design for ie6

Pat
+1  A: 

form method=get WILL put all the form's input into the URL.

It's true that browsers have a maximum length for the URL. It changes from browsers to browsers, and surely from Browsers version to browsers version.

If you can, I would recommend you to use POST for your form.

HTH

vIceBerg
+1  A: 

GET and url ?name=value&... are the same thing, as the browser merely converts a GET form to a URL before sending the request.

The maximum length of the URL is determined at the browser and server level so, for a given browser/server, it's the smaller of the two.

This post has a good list of current max lengths for URLS

Bill James
A: 

This isn't an answer to your question about get and post but in a situation like you are describing it is quite often easier to store the more complex data on the server and associate it with a session id or a user account rather than putting it into the URL every time. Then you can use just the identifier for that session in a cookie or as a url parameter to retrieve the image.

That can also help you to cache the requested images so you don't have to go through the work of regenerating them every time a user wants to look at a particular chart again.

glenatron
+1  A: 
erickson
+2  A: 
mkoeller
+1, I like the caching argument.
Sunny