Might be this is the first interview question by the viva board. Which is very basic and you have to explain clearly. That’s why i am trying to write the post “Basic difference between GET and POST method”. In general view basically both method is used for submitting data into server. Please find the differences from below:
1. GET request is sent via URL.
2. Post request is sent via HTTP request body or you can say internally.
Get Method Indication:
<html> <body> <Form method="GET" Action="http://search.yahoo.com/bin/search"> Name: <input type="Text" name="Name" /> <input type="submit" value="Check" /> </Form> </body> </html>
Form Default Method:
1. GET request is the default method.
2. You have to specify POST method within form tag like <Form method=”POST”…….
1. Since GET request is sent via URL, so that we can not use this method for sensitive data data.
2. Since Post request encapsulated name pair values in HTTP request body, so that we can submit sensitive data through POST method.
1. GET request has a limitation on its length. The good practice is never allow more than 255 characters.
2. POST request has no major limitation. Read discussion part later of this article.
Caching or Bookmarking:
1. GET request will be better for caching and bookmarking.
2. POST request has not.
1. GET request is SEO friendly.
2. POST request has not.
1. GET request always submitted data as TEXT.
2. POST request has no restriction.
1. SEARCH will be the best example for GET request.
2. LOGIN will be the best example for POST request.
HTTP Request Message Format:
GET /path/file.html?SearchText=Interview_Question HTTP/1.0 From: firstname.lastname@example.org User-Agent: HTTPTool/1.0 [blank line here]
POST /path/script.cgi HTTP/1.0 From: email@example.com User-Agent: HTTPTool/1.0 Content-Type: application/x-www-form-urlencoded Content-Length: 8 Code=132
Some comments on the limit on QueryString / GET / URL parameters Length:
1. 255 bytes length is fine, because some older browser may not support more than that.
2. Opera supports ~4050 characters.
3. IE 4.0+ supports exactly 2083 characters.
4. Netscape 3 -> 4.78 support up to 8192 characters.
5. There is no limit on the number of parameters on a URL, but only on the length.
6. The number of characters will be significantly reduced if you have special characters like spaces that need to be URLEncoded (e.g. converted to the ‘%20’).
7. If you are closer to the length limit better use POST method instead of GET method.