国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

區分ASP.NET中get方法和post方法

2024-07-10 13:29:32
字體:
來源:轉載
供稿:網友

我們都知道,get是從服務器上獲取數據,post是向服務器上傳數據。本文主要介紹ASP.NET中get方法和post方法的區別,需要的朋友可以參考下

在網頁設計中,無論是動態還是靜態,get方法是默認的,它在URL地址長度是有限的,所以get請求方法能傳送的數據也是有限的,一般get方法能傳遞256字節的數據,當get請求方法傳遞的數據長度不能滿足需求時,就需要采用另一種請求方法post,post方法可傳遞的數據最大值為2mb相應地,讀取post方法傳遞過來的數據時,需要采用form方法來獲取;post方法在aspx頁面執行時,地址欄看不到傳送過來的參數數據,更加有利于頁面的安全,所以一般情況采用post方法傳送頁面數據。

這里舉個簡單的例子:

get方法

html頁面:

 

 
  1. <html xmlns="http://www.w3.org/1999/xhtml" >  
  2. <head>  
  3. <title>發送GET請求</title>  
  4. </head>  
  5. <body>  
  6. <center > 

發送GET請求

 

 
  1. <hr />  
  2. <form action=default7.aspx method =get >  
  3. 輸入發送的內容:  
  4. <input type =text name="content1" />  
  5. <br />  
  6. <input type =submit value ="發送" />  
  7. </form>  
  8. </center>  
  9. </body>  
  10. </html>  

對應的aspx頁面:

 

  1. <html xmlns="http://www.w3.org/1999/xhtml" >  
  2. <head runat="server">  
  3. <title>接收GET請求</title>  
  4. </head>  
  5. <body>  
  6. <center >  

接收GET方法傳來的內容:

 

  1. <hr />  
  2. <%  
  3. string content = Request.QueryString["content1"];  
  4. Response.Write("GET方法發送過來的內容為:"+content);  
  5. %>  
  6. </center>  
  7. </body>  
  8. </html>  

post方法

html頁面:

 

 
  1. <html xmlns="http://www.w3.org/1999/xhtml" >  
  2. <head>  
  3. <title>發送post請求</title>  
  4. </head>  
  5. <body>  
  6. <center >  

發送post請求
 

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

輸入發送的內容:

 

 
  1. <input type =text name="content1" />  
  2. <br />  
  3. <input type =submit value ="發送" />  
  4. </form>  
  5. </center>  
  6. </body>  
  7. </html>  

對應的aspx頁面:

 

 
  1. <html xmlns="http://www.w3.org/1999/xhtml" >  
  2. <head runat="server">  
  3. <title>接收post請求</title>  
  4. </head>  
  5. <body>  
  6. <center >  

接收post方法傳來的內容:

 

 
  1. <hr />  
  2. <%  
  3. string content=Request .Form ["content1"];  
  4. Response.Write("POST方法發送過來的內容為:"+content);  
  5. %>  
  6. </center>  
  7. </body>  
  8. </html>  

用get方法,當執行aspx頁面時,地址欄的顯示有一段字符“?content1=html輸入的值”,而用post方法,沒顯示,相比之下,post方法比較安全適用。

以上就是本文的全部內容,大家應該對get方法和post方法存在的區別有所了解了吧,希望本文對大家的學習有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 滁州市| 砚山县| 岢岚县| 建宁县| 方山县| 六盘水市| 汤阴县| 岑溪市| 景德镇市| 盐亭县| 甘泉县| 张北县| 大田县| 石景山区| 南平市| 大渡口区| 东乡县| 竹北市| 偃师市| 新绛县| 革吉县| 丰台区| 巩义市| 贺州市| 磴口县| 商城县| 越西县| 教育| 沧州市| 淮南市| 象山县| 青岛市| 金溪县| 红桥区| 高雄县| 延津县| 虞城县| 曲阜市| 于田县| 芷江| 湟源县|