DotNet Mirror
  DNM facebook   DNM Google+   DNM Twitter   

GET and POST methods in ASP.NET/HTML and difference between GET and POST (GET vs POST)

By Ashok Nalam on 12 Dec 2012 | Category: ASP.NET | Tagged: GET POST HTML HTTP 
In this article we will discuss the form submission methods GET and POST with examples and differences of them.
  Discuss Add Comment   |  
Add rating Rate this resource  [Rated 5.00/5 by 1 people] 

Introduction

In this article we will discuss the form submission methods GET and POST with examples and differences of them.

The Get/Post methods are used to send client information to web server. The methods are specified in inside form element using method attribute.

Syntax:

<form method="get|post">
The method attribute uses either get or post. Default is GET method.

GET method:

This method appends form data to page request URL with key value pairs called as query string.

E.g.: http://www.dotnetmirror.com/home.htm?key1=value1&key2=value2 \

  • Page request URL and the form data information (query string) are separated by the ? Character.
  • Get method is restricted to send up to 1024 characters only.
  • Never use Get method to send sensitive information like password, login information to web server.
  • Form data support only ASCII characters.Cannot used to send binary information like word document, text file and image data to server.
  • We can access query string in ASP.NET using Request.QueryString["key1"]

Example: Usage of Get method In ASP.NET/HTML:

In the below example we will see how GET method passed data from login.html (client) to login.aspx page (server).

Login.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>
Output:


Login.aspx

<html>
<body>
<form id="form1" runat="server">
<div>
Welcome <b><% Response.Write(Request.QueryString["username"].ToString()); %></b>
</div>
</form>
</body>
</html>
output:

Output Explanation: Login.html has username data which is sent using get method to login.aspx (server). In the output of second screen shot we can see there is key (username) value(DotNetMirror) data as query stirng in the URL which is submitted to login.aspx page and the output(Welcome DotNetMirror) is show in login.aspx page.

 Post Method:

  • POST method transfers information over HTTP headers.
  • Data transfer through HTTP headers so using secure HTTP protocol we can make sure that data is secured.
  • No restriction on sending data size via Post and also we can send binary data or ASCII information using POST method.
  • We can access form data in ASP.NET using Request.Form["key1"]

Example: Usage of Get method In ASP.NET/HTML:

In the below example we will see how POST method passed data from login.html (client) to login.aspx page (server).

Login.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>
Output:


Login.aspx

<html>
<body>
<form id="form1" runat="server">
<div>
Welcome <b><% Response.Write(Request.Form["username"].ToString()); %></b>
</div>
</form>
</body>
</html>
output:


Output Explanation: Login.html has username data which is sent using post method to login.aspx (server).The output (Welcome DotNetMirror) is show in login.aspx page.

Note: we can observe the post method did not send any query string like what we have seen in get method. Fig2 has query string where Fig4 does not have data in URL.

Usage of Post method:   

  • If the form data is large then use POST method because GET method cannot handle long URL’s
  • Form data contains Non-ASCII characters use POST because GET doesn’t support it.

 Difference between GET and Post:

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
Not visible 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
Bit 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
Can be used for any amount of data
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

  Discuss Add Comment    
Add rating Rate this resource  [Rated 5.00/5 by 1 people] 
About the Contributor
Member Since : 10 Dec 2012
Member Points (Level) : 6453  (Expert)
Location : INDIA
Home Page : http://dotnetmirror.com
About : I am admin of this site.
Rate this resource
 
Advertisement
Add your Comment
Name Email WebSite
Captcha Refresh


Comments (55)
 
1. By on 11 Dec 2016

 
2. By on 11 Dec 2016

 
3. By Barnypok on 27 Dec 2016

utQNgc http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
4. By Barnypok on 27 Dec 2016

u0LzMH http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
5. By Barnypok on 27 Dec 2016

YQUqPd http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
6. By Barnypok on 28 Dec 2016

9u90ge http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
7. By Barnypok on 28 Dec 2016

lLjr2a http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
8. By Barnypok on 28 Dec 2016

nPU8Kh http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
9. By Barnypok on 28 Dec 2016

eM0URS http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
10. By Barnypok on 28 Dec 2016

fLLQS2 http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
11. By Barnypok on 29 Dec 2016

GrOAzG http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
12. By Barnypok on 29 Dec 2016

kIPTeH http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
13. By Barnypok on 29 Dec 2016

U7WRCS http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
14. By Barnypok on 31 Dec 2016

FFml8l http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
15. By Barnypok on 02 Jan 2017

APQQYA http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
16. By Barnypok on 02 Jan 2017

D4bIpu http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
17. By Barnypok on 03 Jan 2017

6tmonL http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
18. By Barnypok on 06 Jan 2017

bkQYl6 http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
19. By Barnypok on 06 Jan 2017

JpHvjZ http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
20. By Barnypok on 06 Jan 2017

8wFIu9 http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
21. By Barnypok on 07 Jan 2017

3XfnkI http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
22. By Barnypok on 08 Jan 2017

Yv4S5S http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
23. By Barnypok on 08 Jan 2017

ZNRzam http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
24. By Barnypok on 08 Jan 2017

BHIWDR http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
25. By Barnypok on 08 Jan 2017

OJWj8l http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
26. By Barnypok on 09 Jan 2017

9OoUyM http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
27. By JimmiXzS on 09 Jan 2017

cL59hS http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
28. By JimmiXzS on 09 Jan 2017

UwiNVM http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com

 
29. By matt on 29 Jan 2017

JyAX1p http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
30. By matt on 29 Jan 2017

ECQk3L http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
31. By chaba on 29 Jan 2017

f0g2RN http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
32. By chaba on 29 Jan 2017

a5m4Ib http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
33. By chaba on 29 Jan 2017

ksPAkv http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
34. By chaba on 29 Jan 2017

m8CEJA http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
35. By matt on 29 Jan 2017

eDTvx9 http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
36. By chaba on 30 Jan 2017

Jr5S3E http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
37. By matt on 30 Jan 2017

yxWF2j http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
38. By chaba on 30 Jan 2017

MNhcQ4 http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
39. By chaba on 30 Jan 2017

d5wdek http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
40. By matt on 30 Jan 2017

bbZ9Wu http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
41. By matt on 30 Jan 2017

TrKaPy http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
42. By chaba on 30 Jan 2017

fBI0ZC http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
43. By matt on 30 Jan 2017

f7gJs0 http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
44. By chaba on 30 Jan 2017

SpjrEo http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
45. By matt on 30 Jan 2017

7VxU3c http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
46. By chaba on 30 Jan 2017

BFAdeD http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
47. By matt on 30 Jan 2017

u0weyU http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
48. By gordon on 31 Jan 2017

I7jeYI http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
49. By gordon on 31 Jan 2017

UioDOO http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
50. By gordon on 31 Jan 2017

73ZniZ http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
51. By gordon on 31 Jan 2017

uxptwH http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
52. By gordon on 01 Feb 2017

4ApqP8 http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
53. By gordon on 01 Feb 2017

tbXAQo http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
54. By gordon on 01 Feb 2017

nrzPkm http://www.y7YwKx7Pm6OnyJvolbcwrWdoEnRF29pb.com

 
55. By JimmiXzSw on 19 Feb 2017

jyhswr http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com