Difference Between HttpGet and HttpPost Method
Difference Between HttpGet and HttpPost Method
Ke y wo rd s : h t t p G ET a n d h t t p PO ST Me t h o d s , h t t p g e t , h t t p p o s t , Di i ffe re n ce b e t we e n
h t t p G ET a n d h t t p PO ST Me t h o d s
T he Hypertext Transfer Protocol (HTTP) is a communication protocol that is designed to enable request-
response between clients and servers. Here, a web browser is the client and an application on a
computer that hosts a web site is the server
Take an html form named "get_form.htm" and write the following code.
1. <html>
2. <head>
3. <title>Using Http Get Method</title>
4. </head>
5. <body>
6. <form id="frm_get" action=" Receiving_Get_Form.aspx" target="_blank"
method="GET" >
7. <table>
8. <tr>
9. <td>First Name : </td> <td><input type="text" id="txtF_Name" name="F_name" />
</td>
10. </tr> <tr>
11. <td>Last Name : </td> <td><input type=" text" id="txtL_name" name="L_name" />
</td>
12. </tr> <tr>
13. <td>Email-Id : </td> <td><input type="text" id="txtE_mail" name="E_mail" />
</td>
14. </tr> <tr>
15. <td>Password: </td> <td><input type="password" id="txtP_word" name="P_word"/>
</td>
16. </tr> <tr>
17. <td><input type="submit" value="Submit" /></td>
18. </tr>
19. </table>
20. </form> </body>
http://www.dotnet-tricks.com/Tutorial/aspnet/bPTF281212-Difference-between-HttpGet-and-HttpPost-Method.html 1/5
6/28/2014 Difference between HttpGet and HttpPost Method
21. </html>
When we click submit button of this form, it will be redirected to "Receiving_Get_Form.aspx" in a new
window.
Page.Request.QueryString["param_name"]
The First Name, Last Name, Email-Id and Password text boxes of get_form.htm form will be sent as
parameter of query string with the field name are F_name, F_name, E_mail and P_word respectively. The
name of query string fields automatically taken from name attribute of each HTML element, so don’t
forget to specify the name attribute So that values should be retrieving using Page.Request.QueryString
["param_name"] here in "Receiving_Get_Form.aspx" automatically.
HttpPost method
The POST request method is designed to request that a web server accepts the data enclosed in the
request message's body for storage
Take an html form named “post_form.htm" and write the following code.
1. </head>
2. <body>
3. <form id="frm_post" action=" Receiving_Post_Form.aspx" target="_blank"
method=" POST" >
4. <table>
5. <tr>
6. <td>First Name : </td> <td><input type="text" id="txtF_Name" name="F_name" />
</td>
7. </tr> <tr>
8. <td>Last Name : </td> <td><input type=" text" id="txtL_name" name="L_name" />
</td>
9. </tr> <tr>
10. <td>Email-Id : </td> <td><input type="text" id="txtE_mail" name="E_mail" />
</td>
11. </tr> <tr>
12. <td>Password: </td> <td><input type="password" id="txtP_word" name="P_word"/>
</td>
13. </tr> <tr>
14. <td><input type="submit" value="Submit" /></td>
15. </tr>
16. </table>
17. </form> </body>
18. </html>
http://www.dotnet-tricks.com/Tutorial/aspnet/bPTF281212-Difference-between-HttpGet-and-HttpPost-Method.html 3/5
6/28/2014 Difference between HttpGet and HttpPost Method
When we click submit button of this form, it will be redirected to "Receiving_Post_Form.aspx" (opened in
new window too). In ASP.NET, if data passed through HTTP Post method we need the following code to
retrieve the data (as written in "Receiving_Post_Form.aspx").
Page.Request.Form["param_name"]
Values of "post_form.htm"(that used method="POST") form sent using POST method therefore, the URL
still intact, we retrieve The First Name, Last Name, Email-Id and Password text using
Page.Request.Form["param_name"] value taken from the name each of HTML element of second form
(Once again don’t forget to specify name attribute for all textboxes so that we are able to get value
automatically here in this page). When you click Submit button, values of "post_form.htm" passed to
"Receiving_Post_Form.aspx".
http://www.dotnet-tricks.com/Tutorial/aspnet/bPTF281212-Difference-between-HttpGet-and-HttpPost-Method.html 4/5
6/28/2014 Difference between HttpGet and HttpPost Method
8. It is advisable for sending critical data which should not visible to users.
Print Article
Tw eet
Shailendra Chauhan works as Software Analyst at reputed MNC and has more than 5 years of hand
over Microsoft .NET technologies. He is a .NET Consultant and is the founder & chief editor of
www.dotnet-tricks.com and www.dotnetinterviewtricks.com blogs. He is an author of book ASP.NET
MVC Interview Questions and Answers.
He loves to work with web applications and mobile apps using Microsoft technology including ASP.NET,
MVC, C#, SQL Server, WCF, Web API, Entity Framework,Cloud Computing, Windows Azure, jQuery,
jQuery Mobile, Knockout.js, Angular.js and many more web technologies. More...
http://www.dotnet-tricks.com/Tutorial/aspnet/bPTF281212-Difference-between-HttpGet-and-HttpPost-Method.html 5/5