Thursday, 16 August 2012

Difference Between Get And Post method in ASP.Net

So many new programmer are confused about post and get method for send the data. In this article i discuss about this .

The first question arise that what is the get and post method
so many developer confused he/she said that get is used for get the data from server and post  is used for post the data in server this is totally wrong(in starting i am also said this ).
Both Get and Post Method are form submission method.it is used for send the data from client side to server side.

The  Second Question where it is  .
The method is inside the form tag like below
syntax is like below 

<form method="get||post">
you use single method name get or post  

Third Question is ByDefault which method is used 
Ans is By default Get method are used 

Now we discuss these method individually  
What is the difference between these two method 

GET
POST
Data will be arranged in HTTP header by appending to the URL as query string
Data will be arranged in HTTP message body.
Data is in query string so user can view the data
Data is not shown to user
Less secured compared to POST method because data is in query string so it will be saved in browser history and web server logs
safer than GET method because data is not saved in history or web server logs.
As data is saved in URL so its saves only 2048 bytes data
We can used any amount of data and any format
Can be bookmarked
Can’t bookmarked
Hacking will be easy
Hacking is difficult
Only ASCII character data type allowed
No restrictions. Allows binary data also
Caching is possible
No caching

When Use Post Method 
    If the form data is large  then best is use  POST method because GET method cannot      handle long  Url.
   Form data contains Non-ASCII characters use POST because GET doesn’t support it.

Example: Usage of Get method In ASP.NET:
In the below example we will see how GET method passed data from abc.html (client) to login.aspx page (server).
abc.html
<html>
<body>
<form method="get" action="login.aspx">
   User Name: <input id="txtuserName" type="text" name="username" />       
    <input id="btnSubmit" type="submit" value="Submit data using GET" />
    </form>
</body>
</html>
login.aspx
<html>
<body>
    <form id="form1" runat="server">
    <div>
    Welcome <b><% Response.Write(Request.QueryString["username"].ToString()); %></b>
    </div>
    </form>
</body>
</html>




Post Method:
  • We can access form data in ASP.NET using Request.Form["key1"]
 Example: Usage of Post method In ASP.NET:
abc.html
<html>
<body>
<form method="post" action="login.aspx">
   User Name: <input id="txtuserName" type="text" name="username" />       
    <input id="btnSubmit" type="submit" value="Submit data using POST" />
    </form>
</body>
</html>
login.aspx
<html>
<body>
    <form id="form1" runat="server">
    <div>
    Welcome <b><% Response.Write(Request.Form["username"].ToString()); %></b>
    </div>
    </form>
</body>
</html>
Output:
Login.html



 

18 comments:

  1. Now I got the real working of get and post method

    ReplyDelete
  2. Nice article....very much helping

    ReplyDelete
  3. Nice article. Tnx man

    ReplyDelete
  4. Sorry, but I do not understand why, in both cases, you use the form method="get"?

    ReplyDelete
  5. sorry i rectify it .. thanks for your error mark

    ReplyDelete
  6. really awesome i had not knowledge about it how to use get and post and what actually it is but now i am totally clear with this topic thanks rohit :)

    ReplyDelete
  7. gud article.before that i did not know about that....

    ReplyDelete
  8. Nice and simple

    ReplyDelete
  9. very informative.. Thanks.
    Have a look at this link http://www.etechpulse.com/2012/10/what-is-difference-between-get-and-post.html

    ReplyDelete
  10. Hi Rohit,

    Could you pls confirm how did you host your own website http://www.rohitwebstudy.com/?

    How much cost incurred for it?

    Your guidance will help a lot!!!

    Thanks,
    Ashish

    ReplyDelete
  11. Very well explained. Thank u

    ReplyDelete
  12. Simple and thanks

    ReplyDelete
  13. gud one.normally people guess wrong these two method

    ReplyDelete
  14. Great Job!!!!!

    ReplyDelete
  15. I can't about ABC.HTML, how it work in asp.net

    ReplyDelete