What is GET and POST method in HTTP and HTTPS Protocol? Answer (original) (raw)
What is GET HTTP Request in HTTP Protocol?
HTTP protocol supports several request methods you can use while sending requests using HTTP or HTTPS protocol. GET is one of them.
As the name suggests the GET method is to retrieve a page from the HTTP Server. You can identify a GET request by looking method attribute on the HTTP Request part.
If you are using Netbeans IDE for Java web development you can enable HTTP Server monitor which can capture HTTP requests and show details of request parameters, headers, and other useful information.
For GET HTTP request method will be GET for example almost all the URL which is accessible using link are accessed using HTTP Request.
One important property of GET request is that any request parameter or query parameter is passed as URL encoded string, appended using "?" character which makes it non-secure because whatever information you pass in URL String is visible to everybody.
Though GET method has some very interesting and powerful use cases which we will see in the next section: When to use GET HTTP Request?
When to use HTTP GET Request?
As I said GET method is not secure and hence not a suitable choice for transferring confidential data but GET method is extremely useful for retrieving static content from web server. here are some examples where a using GET method make sense:
There is no side effect of repeated request. for example clicking a link which points to another page. it doesn't matter if you click the link twice or thrice , This also gives chance browser of the server to catch the response for faster retrieval.
You are not passing any sensitive and confidential information. instead you just passing some configuration data or session id.
You want URL pointed by HTTP GET request to be bookmark-able.
Data requires to be sent to Server is not large and can safely accommodate in the maximum length of URL supported by all browsers. In general different browser has a different character limit for URL length but having it under the limit is a good choice.
What is the POST HTTP method?
POST HTTP request is denoted by the method: POST in the HTTP request. In POST method data is not sent as part of a URL string to server instead in POST, data is sent as part of message body.
Almost all authentication request is sent via POST method in HTTP world. POST method is secure because data is not visible in URL String and can be safely encrypted using HTTPS for further security.
All sensitive and confidential information sent to be server must go on POST request and via HTTPS (HTTP with SSL). POST method is also used for submitting information to server, any information which can alter state of application like adding item into shopping cart, making payments etc. here are some examples where you should consider using POST method in HTTP request:
Use POST if you are sending large data which can not be fit into URL in case of GET.
Use the POST method if you are passing sensitive and confidential information to server e.g. user_id, password, account number etc.
Use the POST method if you are submitting data that can alter the state of application e.g. adding items into cart for passing that cart for payment processing.
Use POST if you are writing a secure application and don't want to show query parameters in the URL. You can further see these Servlet and JSP courses to learn more about the POST method and how they are processed in Java.
Difference between GET and POST method in HTTP Protocol
Most of the difference between GET and POST has been already discussed in there respective sections. It all depends upon requirement when you want to choose GET and POST and knowledge of these differences help you to make that decision.
GET method passes request parameter in URL String while POST method passes the request parameter in request body.
GET request can only pass limited amount of data while POST method can pass large amount of data to server.
GET requests can be bookmarked and cached unlike POST requests.
GET is mostly used for view purpose (e.g. SQL SELECT) while POST is mainly use for update purpose (e.g. SQL INSERT or UPDATE).
That’s all on What is GET and POST methods in http protocol and difference between GET and POST http request. The key point is to know where to use GET request and where to use POST request.
Other Servlet JSP tutorial you may like: