使用get方法获取页面的form内容
新建一个getform.html
<html> <head> <title>Using Http Get Method</title> </head> <body> <form id="frm_get" action=" Receiving_Get_Form.aspx" target="_blank" method="GET" > <table> <tr> <td>First Name : </td> <td><input type="text" id="txtF_Name" name="F_name" /></td> </tr> <tr> <td>Last Name : </td> <td><input type=" text" id="txtL_name" name="L_name" /></td> </tr> <tr> <td>Email-Id : </td> <td><input type="text" id="txtE_mail" name="E_mail" /></td> </tr> <tr> <td>Password: </td> <td><input type="password" id="txtP_word" name="P_word"/> </td> </tr> <tr> <td><input type="submit" value="Submit" /></td> </tr> </table> </form> </body> </html>
新建一个Receiving_Get_Form.aspx页面
<%@ page language="C#" AutoEventWireup="true" codeFile="Receiving_ Get_Form.aspx.cs" Inherits="Receiving_ Get_Form"% > <html> <head> <title>Data Received Here </title> </head> <body> <table border="1" cellpadding="6" cellspacing="3" > <tr> <td>First Name : </td> <td> <% Response.Write(Page.Request.QueryString["F_name"]); %> </td> </tr> <tr> <td>Last Name : </td> <td> <% Response.Write(Page.Request.QueryString["L_name"]); %> </td> </tr> <tr> <td>Email-Id : </td> <td> <% Response.Write(Page.Request.QueryString["E_mail"]); %> </td> </tr> <tr> <td>Password : </td> <td> <% Response.Write(Page.Request.QueryString["P_word"]); %> </td> </tr> </table> </body> </html>
- GET - Requests data from a specified resource
- An hyperlink or anchor tag that points to an action will ALWAYS be an HttpGet.
- Data is submitted as a part of url.
- Data is visible to the user as it posts as query string.
- It is not secure but fast and quick.
- It use Stack method for passing form variable.
- Data is limited to max length of query string.
- It is good when you want user to bookmark page.
使用post获取表单内容
</head> <body> <form id="frm_post" action=" Receiving_Post_Form.aspx" target="_blank" method=" POST" > <table> <tr> <td>First Name : </td> <td><input type="text" id="txtF_Name" name="F_name" /></td> </tr> <tr> <td>Last Name : </td> <td><input type=" text" id="txtL_name" name="L_name" /></td> </tr> <tr> <td>Email-Id : </td> <td><input type="text" id="txtE_mail" name="E_mail" /></td> </tr> <tr> <td>Password: </td> <td><input type="password" id="txtP_word" name="P_word"/> </td> </tr> <tr> <td><input type="submit" value="Submit" /></td> </tr> </table> </form> </body> </html>
<%@ page language="C#" AutoEventWireup="true" codeFile="Receiving_Post_Form.aspx.cs" Inherits=" Receiving_Post_Form"% > <html> <head> <title>Data Received Here </title> </head> <body> <table border="1" cellpadding="6" cellspacing="3" > <tr> <td>First Name : </td> <td> <% Response.Write(Page.Request.Form["F_name"]); %> </td> </tr> <tr> <td>Last Name : </td> <td> <% Response.Write(Page.Request.Form["L_name"]); %> </td> </tr> <tr> <td>Email-Id : </td> <td> <% Response.Write(Page.Request. Form["E_mail"]); %> </td> </tr> <tr> <td>Password : </td> <td> <% Response.Write(Page.Request. Form["P_word"]); %> </td> </tr> </table> </body> </html>
- POST - Submits data to be processed to a specified resource
- A Submit button will always initiate an HttpPost request.
- Data is submitted in http request body.
- Data is not visible in the url.
- It is more secured but slower as compared to GET.
- It use heap method for passing form variable
- It can post unlimited form variables.
- It is advisable for sending critical data which should not visible to users.
时间: 2024-12-07 02:05:37