stock quote

10/16/08

The difference of HTTP POST and GET

Reminder me of the Web basics.

When doing a form submit from client side (web browser) to the server,
POST allows you to send more data then 1024 chars in tunnel
GET will append all your data in the URL section <= 1024 chars

So in my Ext.Ajax.request(), if sending a lot of data like a JsonData object of a whole grid, use config: method: POST

See: http://www.jguru.com/faq/view.jsp?EID=56472

Answer
GET and POST basically allow information to be sent back to the webserver from a browser (or other HTTP client for that matter).

Imagine that you have a form on a HTML page and clicking the "submit" button sends the data in the form back to the server, as "name=value" pairs.

Choosing GET as the "method" will append all of the data to the URL and it will show up in the URL bar of your browser. The amount of information you can send back using a GET is restricted as URLs can only be 1024 characters.

A POST on the other hand will (typically) send the information through a socket back to the webserver and it won't show up in the URL bar. You can send much more information to the server this way - and it's not restricted to textual data either. It is possible to send files and even binary data such as serialized Java objects!

A PUT allows you to "put" (upload) a resource (file) on to a webserver so that it be found under a specified URI. DELETE allows you to delete a resource (file). These are both additions to HTTP/1.1 and are not usually used. HEAD returns just the HTTP headers for a resource. TRACE and OPTIONS are also HTTP/1.1 additions and also rarely used.

The Servlet spec allows you to implement separate Java methods implementing each HTTP method in your subclass of HttpServlet. Override the doGet() and/or doPost() method to provide normal servlet functionality. Override doPut() or doDelete() if you want to implement these methods. There's no need to override doOptions() or doTrace(). And the superclass handles the HEAD method all on its own.


No comments: