一、form里面的action和method的post使用方法
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="formsubmitpost.aspx.cs" Inherits="formsubmitpost" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server" action="formsubmitget.aspx" method="post"> <div> <input id="b" name="b" value="123" /> <input id="w" type="submit" /> </div> </form> </body> </html>
當你點擊button按鈕提交的時候,瀏覽器的地址為http://localhost:1621/formsubmitpost.aspx,頁面會刷新但是地址不變
二、form里面的action和method的get使用方法
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="formsubmitget.aspx.cs" Inherits="formsubmitget" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server" action="formsubmitget.aspx" method="get"> <div> <input id="a" name="a" value="123" /> <input id="w" type="submit" /> </div> </form> </body> </html>
但你點擊button提交的時候,瀏覽器地址為http://localhost:1621/formsubmitget.aspx?__VIEWSTATE=%2FwEPDwUKLTEzNDM3NzkxOWRkeBFIL8xbs6u8bVKlOO5sf6FSAk0OTJ6ZUC4n2AN9oe4%3D&a=123&__VIEWSTATEGENERATOR=4B2C1984
而這個地址包含你傳過去的值。
綜上,
get:
1>通過GET提交數據,用戶名和密碼將明文出現在URL上,因為登錄頁面有可能被瀏覽器緩存,GET請求請提交的數據放置在HTTP請求協議頭
2>或者其他人查看瀏覽器的歷史紀錄,那么別人就可以拿到你的賬號和密碼了,除此之外,使用GET提交數據還可能會造成Cross-site request forgery攻擊,所以不安全
3> GET請求有長度限制
post:
1>POST數據放在body(POST提交的數據則放在實體數據),POST請求數據不能被緩存下來
2> POST請求參數不會被保存在瀏覽器歷史或 web 服務器日志中。
3> POST請求沒有長度限制
