Skip to main content

Get & Post method



GET and POST http Methods

Tragically there is a considerable misuse of GET over POST and the other way around. Both HTTP strategies can accomplish similar objectives, however an off base decision between them can prompt sudden and conceivably destructive results. In this way, to ensure we get things right, I present to you the conclusive guide of how to choose and use a GET or POST method easily :)
Firstly, I’ll show you how to identify GET and POST methods. See the below defines.

  • GET - Requests data from a specified resource
  • POST - Submits data to be processed to a specified resource

Simple Structures of GET and POST

The query string (value pairs/name) is sent in the URL of a GET request:
GET /test/demoForm.php?name1=value1&name2=value2 HTTP/1.1
Host:webtech.com
and in the body of POST requests:
POST /test/demoForm.php HTTP/1.1
Host:webtech.com
name1=value1&name2=value2


>> I have added code snippets of the GET and POST methods for your much clearance.

GET method
I will show you how to use GET method and what is the result of the after submitting the form data.

set_form.html

<html>
    <head>
        <title>FORM</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div>GET method</div>
        <form action="index.html" method="GET">
           FirstName:<input type="text" name="fname" value="" /><br>
           LastName:<input type="text" name="lname" value="" /><br>
           <input type="submit" value="Submit" name="Submit" />
        </form>
    </body>
</html>

RESULT (index.html)
*See the URL after submit the form data.

we can see that when using GET method what are the data that  we submitted ,will appended to the url and sent along with the header information.

------------------------------------------------------------------------------------------------------------------------------------------

POST method
set_form.html
<html>
    <head>
        <title>FORM</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div>GET method</div>
        <form action="index.html" method="POST">
           FirstName:<input type="text" name="fname" value="" /><br>
           LastName:<input type="text" name="lname" value="" /><br>
           <input type="submit" value="Submit" name="Submit" />
        </form>
</body>
</html>


RESULT (index.html)
*See the URL after submit the form data.
From this result of URL we can identify that data that what we submit will not appended with the URL.
Those parameters are sent separately without appending to the URL.

Above examples will surely help to you when identifying the results of GET and POST methods and how to use that methods.


Rules for when using GET or POST
I have mention here most important 04 rules that you must consider when dealing with GET and POST.
#Rule01: Use POST when dealing with sensitive data.
Because query strings are moved transparently in GET asks for, we need to consider our security and that of our clients when managing very sensitive information like passwords or MasterCard numbers
#Rule 02: Use POST when dealing with long requests.
#Rule 03: Use GET in AJAX environments.
#Rule 04: Use GET for small amount of data and insensitive data send.

Finally, I hope this guidance will prevent you from misuse of GET and POST methods.

Comments

  1. Very nice article.....................

    ReplyDelete
  2. Got a real good idea about get & post methods..Thumbs up from me....

    ReplyDelete
  3. Great work sis!! Keep it up.. I propose you to write about all the superglobal variables..

    ReplyDelete
  4. very use full article , !!!

    ReplyDelete

Post a Comment