Click to See Complete Forum and Search --> : Difference between GET & POST Methods
sridhar_423
11-14-2007, 10:46 AM
Hello all,
Good day to you.
I have one very basic doubt about the GET and POST methods.
As far as I know --
GET means, the data that is sent gets appended to the URL.(If at all we try to pass anything in the HTTP body, it gets ignored)
POST means, the data is passed in the HTTP body. Advantage is that if at all any arguments are passed as part of URL, they'll also be considered as part of request.
HEAD means, all the body and arguments(if any) passed in the url will be ignored. Only the header information of the request is considered.
Is my understanding correct?
Awaiting your precious comments/suggestions/clarifications.
Thanks,
Sridhar Talatam
sridhar_423
11-14-2007, 10:57 AM
Small correction to my post..
If at all we try to pass anything in the HTTP body, it gets appended to the URL.
For POST, the keys passed in URL gets ignored (I checked now)
TJ111
11-14-2007, 11:43 AM
You can have both you know, you don't have to exclusively use one or the other. For example.
<form action="test.php?example=get_statement" method="post">
Now all the information in that form that will be contained in the $_POST superglobal on test.php, but $_GET['example'] will contain "get_statement".
Generally speaking, using GET is just an easy way of passing simple information in a link or something similar (such as this page, look at the URL), where as POST is used for more sensitive information or where much more information needs to be passed. (The submit button on this forum uses POST). Its also just a matter of preference and what you think is easier for your situation.
bokeh
11-14-2007, 04:19 PM
Its also just a matter of preference and what you think is easier for your situation.Well it shouldn't be; you should follow the RFC (2616 section 9 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html)). GET is used for idempotent requests (requests without side effects) and POST for non idempotent ones.
sridhar_423
11-17-2007, 09:41 AM
Dear Bokeh & TJ111,
Thanks for the information provided.
Hey Bokeh .. The Genius,
Very glad to see a reply from you.
I went through the site you have specified. For POST method, its given that data is sent as a subordinate of the request URI i.e. in the Request Body
For GET method, the data is appended to the URL. (As mentioned in sec15.1.3)
I have created two pages. First page is called One.html and Second Page is called vals.php
One.html has a simple HTML form with one element of Input type text.
The action has URL appended with two elements. Something like this..
<form name=myForm method="POST" action="http://localhost/expts/vals.php?GET1=one&GET2=two">
<input type=text name="Element1" value="value1">
</form>
When I submit this form (By setting the Method to GET/ POST), following are the results.
Method: GET
URL Args:NO
Elements in Body:YES
SENT TO vals.php:YES ($_GET & $_REQUEST are same)
URL Args:YES
Elements in Body:YES
SENT TO vals.php:YES, BUT ONLY VARIABLES IN BODY ($_GET & $_REQUEST are same)
Method: POST
URL Args:NO
Elements in Body:YES
SENT TO vals.php:YES ($_GET is Blank,$_POST & $_REQUEST are same)
URL Args:YES
Elements in Body:YES
SENT TO vals.php:YES ($_GET has variables passed from URL, $_POST has variables set in BODY, S_REQUEST has summation of all variables)
Now, I fail to understand the following Points
1. While using POST method, Why the variables appended to the URL are still loaded in $_GET array
2. While using GET method, Why the variables appnded to URL (in the "action" part) are always ignored.
Any ideas are greatly appreciated.
Thanks in Advance,
Sridhar
bokeh
11-17-2007, 10:12 AM
1, Because the POST method does not modify the query string.
2, Because the GET method overwrites (not appends) the query string (to avoid collisions and other problems).
sridhar_423
11-17-2007, 10:26 AM
Hi Bokeh,
Thanks for the clarifications. Its clear for me why GET doesnt consider the keys passed along with URL and POST includes URL parameters as well.
I'll read some more on POST for different cases for clarity. Please let me know if you have any good site to start with..
Thanks again ..
Sridhar
sridhar_423
11-17-2007, 10:41 AM
I think I'm going crazy..
One Last question ..
While using Ajax (GET method), is it mandatory that the body should always be null? i.e. actxObj.send(null)
If no... I have a doubt again regarding the GET method overwriting the Query String. ..
If yes, then its clear for me.
Thanks
Sridhar
bokeh
11-17-2007, 11:04 AM
Put simply a GET request should not contain a message body while a GET response should.
sridhar_423
11-17-2007, 11:08 AM
Okay.. that clears all my doubts..
thanks for your patience :)
Sridhar