在網頁設計中,無論是動態還是靜態,get方法是默認的,它在URL地址長度是有限的,所以get請求方法能傳送的數據也是有限的,一般get方法能傳遞256字節的數據,當get請求方法傳遞的數據長度不能滿足需求時,就需要采用另一種請求方法post,post方法可傳遞的數據最大值為2mb相應地,讀取post方法傳遞過來的數據時,需要采用form方法來獲取;post方法在aspx頁面執行時,地址欄看不到傳送過來的參數數據,更加有利于頁面的安全,所以一般情況采用post方法傳送頁面數據。
這里舉個簡單的例子:
get方法
html頁面:
html xmlns="http://www.w3.org/1999/xhtml" >
head>
title>發送GET請求/title>
/head>
body>
center >
發送GET請求
hr />
form action=default7.aspx method =get >
輸入發送的內容:
input type =text name="content1" />
br />
input type =submit value ="發送" />
/form>
/center>
/body>
/html>
對應的aspx頁面:
html xmlns="http://www.w3.org/1999/xhtml" >
head runat="server">
title>接收GET請求/title>
/head>
body>
center >
接收GET方法傳來的內容:
hr />
%
string content = Request.QueryString["content1"];
Response.Write("GET方法發送過來的內容為:"+content);
%>
/center>
/body>
/html>
post方法
html頁面:
html xmlns="http://www.w3.org/1999/xhtml" >
head>
title>發送post請求/title>
/head>
body>
center >
發送post請求
hr />
form action =default8.aspx method =post >
輸入發送的內容:
input type =text name="content1" />
br />
input type =submit value ="發送" />
/form>
/center>
/body>
/html>
對應的aspx頁面:
html xmlns="http://www.w3.org/1999/xhtml" >
head runat="server">
title>接收post請求/title>
/head>
body>
center >
接收post方法傳來的內容:
hr />
%
string content=Request .Form ["content1"];
Response.Write("POST方法發送過來的內容為:"+content);
%>
/center>
/body>
/html>
用get方法,當執行aspx頁面時,地址欄的顯示有一段字符“?content1=html輸入的值”,而用post方法,沒顯示,相比之下,post方法比較安全適用。
以上就是本文的全部內容,大家應該對get方法和post方法存在的區別有所了解了吧,希望本文對大家的學習有所幫助。
您可能感興趣的文章:- Asp.net XMLHTTP封裝類(GET,Post發送和接收數據)
- ASP.NET的HtmlForm控件學習及Post與Get的區別概述
- ASP.NET Get和Post兩種提交方法淺析
- asp.net頁面與頁面之間傳參數值方法(post傳值和get傳值)