HTTP for HTML Authors, Part III - HTML with Style | 5 | WebReference

HTTP for HTML Authors, Part III - HTML with Style | 5

index1234567

HTTP for HTML Authors, Part III

Form submission through HTTP

Back in Tutorial 13, when I explained HTML forms, I made a brief mention of how they are submitted. That was when you where first introduced to the difference between GET and POST.

Now you know that GET and POST are really two different HTTP request methods. We've already covered the GET method in part I; it simply involves getting a URL. When a form is submitted using the GET method, the submitted data is part of the URL; the browser just encodes the data and tags it on to the end as a query string. What the Web server does with it after this is its own affair.

GET queries are considered antiquated by many, since they have many shortcomings (you can't use characters other than those in ISO-8859-1, for instance, and you usually can't have a URL longer than 1024 bytes), but they do have one distinct advantage: They can be linked to. A POST query is more than just a URL, it is a URL plus a piece of data, so you can't link to a POST query using an A or LINK element, nor can you bookmark it for later use. This is important for form submissions that don't actually change anything. A Web search on a search engine is a good example. The result of the query is a resource; it might be a changing resource as different results may be returned at later times, but it still identifies the set of Web pages that matched your search query. On the other hand, if a form is used to send an e-mail as described above, you won't want to link to it or bookmark it since every time someone follows the link an e-mail will be sent without any confirmation.

POST queries are more sophisticated, but cannot be linked to. As we saw in the mail example above, this can be a blessing; you don't want all kinds of requests being linked to like this. On the other hand, POST queries can cause several problems. For example, take the press release example I mentioned earlier. Let's assume that Acme offers a form so that users can view press releases by selecting a date and title in a form, and then returns the press release after the form is submitted. Let's assume the form's ACTION atribute is the following URL:

http://www.acme.com/news/pressrelease

If this form uses the POST method, the user will get to the press release but the URL shown by his browser, as well as the one used when bookmarking the search, will be the one shown above, which unfortunately does not coincide with the URL that points to the article. Using GET instead, the URL will be something like:

http://www.acme.com/news/pressrelease?year=2000&month=1&day=14&title=foobar

This can then be used to link directly to the press release from anywhere in the Web.

index1234567

Next Page...

http://www.internet.com/

URL: http://www.webreference.com/html/tutorial30/4.html

Produced by Stephanos Piperoglou
Created: March 15, 2001
Revised: March 16, 2001