get方法与post方法的使用

本文介绍如何使用HTTP GET和POST方法从指定资源获取表单内容,并通过实例展示了实现过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用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>
  1.  GET - Requests data from a specified resource

  2. An hyperlink or anchor tag that points to an action will ALWAYS be an HttpGet.

  3. Data is submitted as a part of url.

  4. Data is visible to the user as it posts as query string.

  5. It is not secure but fast and quick.

  6. It use Stack method for passing form variable.

  7. Data is limited to max length of query string.

  8. 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>
  1. POST - Submits data to be processed to a specified resource

  2. A Submit button will always initiate an HttpPost request.

  3. Data is submitted in http request body.

  4. Data is not visible in the url.

  5. It is more secured but slower as compared to GET.

  6. It use heap method for passing form variable

  7. It can post unlimited form variables.

  8. It is advisable for sending critical data which should not visible to users.

 

转载于:https://www.cnblogs.com/Hackerman/p/4772003.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值