Distinguish get method from post method in ASP. NET

  • 2021-07-07 06:58:55
  • OfStack

In web design, Whether dynamic or static, The get method is the default, It has a limited address length in URL, Therefore, the data that get request method can transmit is limited. A general get method can transmit 256 bytes of data. When the data length transmitted by get request method cannot meet the demand, another request method post needs to be adopted. The maximum data that post can transmit is 2mb. Accordingly, when reading the data transmitted by post method, form method needs to be adopted to obtain it. When post method is executed on aspx page, the parameter data transmitted can't be seen in the address bar, which is more conducive to the security of the page. Therefore, post method is used to transmit page data in general cases.

Here's a simple example:

get method

html page:


<html xmlns="http://www.w3.org/1999/xhtml" > 
<head> 
<title> Send GET Request </title> 
</head> 
<body> 
<center > 

Send an GET request


<hr /> 
<form action=default7.aspx method =get > 
 Enter what to send:  
<input type =text name="content1" /> 
<br /> 
<input type =submit value =" Send " /> 
</form> 
</center> 
</body> 
</html> 

Corresponding aspx page:


<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
<title> Receive GET Request </title> 
</head> 
<body> 
<center > 

Receive the content from GET method:


<hr /> 
<% 
string content = Request.QueryString["content1"]; 
Response.Write("GET The content sent by the method is: "+content); 
%> 
</center> 
</body> 
</html> 

post method

html page:


<html xmlns="http://www.w3.org/1999/xhtml" > 
<head> 
<title> Send post Request </title> 
</head> 
<body> 
<center > 

Send an post request


<hr /> 
<form action =default8.aspx method =post > 

Enter what to send:


<input type =text name="content1" /> 
<br /> 
<input type =submit value =" Send " /> 
</form> 
</center> 
</body> 
</html> 

Corresponding aspx page:


<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
<title> Receive post Request </title> 
</head> 
<body> 
<center > 

Receive the content from post method:


<hr /> 
<% 
string content=Request .Form ["content1"]; 
Response.Write("POST The content sent by the method is: "+content); 
%> 
</center>  
</body> 
</html> 

With get method, when executing aspx page, the address bar is displayed with 1 character "? content1=html input value", while with post method, it is not displayed. In contrast, post method is safer and more applicable.

The above is the whole content of this article, we should be on the get method and post method to understand the differences between it, I hope this article is helpful for everyone to learn.


Related articles: