ASP.NET中g(shù)et方法和post方法的區(qū)別
在網(wǎng)頁設(shè)計中,無論是動態(tài)還是靜態(tài),get方法是默認的,它在URL地址長度是有限的,所以get請求方法能傳送的數(shù)據(jù)也是有限的,一般get方法能傳遞256字節(jié)的數(shù)據(jù),當(dāng)get請求方法傳遞的數(shù)據(jù)長度不能滿足需求時,就需要采用另一種請求方法post,post方法可傳遞的數(shù)據(jù)***值為2mb相應(yīng)地,讀取post方法傳遞過來的數(shù)據(jù)時,需要采用form方法來獲取;post方法在aspx頁面執(zhí)行時,地址欄看不到傳送過來的參數(shù)數(shù)據(jù),更加有利于頁面的安全,所以一般情況采用post方法傳送頁面數(shù)據(jù)。
這里舉個簡單的例子:
(get方法)
html頁面:
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head>
- <title>發(fā)送GET請求</title>
- </head>
- <body>
- <center >
發(fā)送GET請求
- <hr />
- <form action=default7.aspx method =get >
- 輸入發(fā)送的內(nèi)容:
- <input type =text name="content1" />
- <br />
- <input type =submit value ="發(fā)送" />
- </form>
- </center>
- </body>
- </html>
對應(yīng)的aspx頁面:
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title>接收GET請求</title>
- </head>
- <body>
- <center >
接收GET方法傳來的內(nèi)容:
- <hr />
- <%
- string content = Request.QueryString["content1"];
- Response.Write("GET方法發(fā)送過來的內(nèi)容為:"+content);
- %>
- </center>
- </body>
- </html>
(post方法)
html頁面:
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head>
- <title>發(fā)送post請求</title>
- </head>
- <body>
- <center >
發(fā)送post請求
- <hr />
- <form action =default8.aspx method =post >
輸入發(fā)送的內(nèi)容:
- <input type =text name="content1" />
- <br />
- <input type =submit value ="發(fā)送" />
- </form>
- </center>
- </body>
- </html>
對應(yīng)的aspx頁面:
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title>接收post請求</title>
- </head>
- <body>
- <center >
接收post方法傳來的內(nèi)容:
- <hr />
- <%
- string content=Request .Form ["content1"];
- Response.Write("POST方法發(fā)送過來的內(nèi)容為:"+content);
- %>
- </center>
- </body>
- </html>
用get方法,當(dāng)執(zhí)行aspx頁面時,地址欄的顯示有一段字符“?content1=html輸入的值”,而用post方法,沒顯示,相比之下,post方法比較安全適用。
【編輯推薦】
- ASP.NET配置文件Web.config詳細解釋
- ASP.Net中保護自定義的服務(wù)器控件
- 一款經(jīng)典的ajax登錄頁面 后臺asp.net
- 使用ASP.NET操作IIS7中使用應(yīng)用程序
- 淺述asp.net海量分頁數(shù)據(jù)存儲過程