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
1. Data will be arranged in HTTP message body.
2.Data is in query string so user can view the data
2.Data is not shown to user
3.Less secured compared to POST method because data is in query string so it will be saved in browser history and web server logs
3.safer than GET method because data is not saved in history
or web server logs.
4.As data is saved in URL so its saves only 2048 bytes data
4.We can used any amount of data and any format
5.Can be bookmarked
5.Can’t bookmarked
6.Hacking will be easy
6.Hacking is difficult
7.Only ASCII character data type allowed
7.No restrictions. Allows binary data also
8.Caching is possible
8.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
No comments :
Post a Comment