[网络收集]form表单提交方式post和get,Request.QueryString,Request.Form

ASP.NET中GET与POST详解
本文详细解析了ASP.NET中GET与POST请求的区别及应用。通过实例演示了如何使用这两种请求方式,并解释了它们在不同场景下的行为差异。特别关注了表单提交时的数据获取方法。

//测试页面FormSubmit.aspx:

//html代码
</head>
<body>
     <form id="form1" runat="server" action="FormSubmit.aspx" method="post">
     <div>    
     <input type="text" name="Text" value="Hello World" /><br />
     <input type="text" name="Text" value="Hello World1" /><br />
     <a href="FormSubmit.aspx?Text=Hello World2">a</a>
     <input type="submit" value="提交" />
     </div>
     </form>
</body>
</html>

 

//cs代码
     protected void Page_Load(object sender, EventArgs e)
     {
         if (Request.QueryString["Text"] != "")
         {
             Response.Write("通过get方法传递来的字符串是: " + Request.QueryString["Text"] + ",<br />通过Request.QueryString

[\"Text\"]获得");
         }
         if (Request.Form["Text"] != "")
         {
             Response.Write("<br /><br />通过Post方法传递来的字符串是: " + Request.Form["Text"] + ",<br />通过Request.Form

[\"Text\"]获得");
         }
         if (Request["Text"] != "")
         {
             Response.Write("<br /><br />字符串是: " + Request["Text"] + ",<br />通过Request[\"Text\"]获得");
         }

     }

//运行结果
通过get方法传递来的字符串是: ,
通过Request.QueryString["Text"]获得

通过Post方法传递来的字符串是: Hello World,Hello World1,
通过Request.Form["Text"]获得

字符串是: Hello World,Hello World1,
通过Request["Text"]获得

//

         //如果IE地址为http://localhost:13409/TempCode/FormSubmit.aspx?Text=Hello+World2,表单提交方式为post方式,测试为post和

get的混合方式
         //将action=""设置成FormSubmit.aspx?Text=Hello World2或者FormSubmit.aspx,对提交方式不影响
         //<a href="FormSubmit.aspx?Text=Hello World2">a</a>,<!--永远是get提交,不管表单form的method属性设置成post还是get;并

且以http://localhost:13409/TempCode/FormSubmit.aspx?Text=Hello%20World2传送;取到的值唯一,为Hello World2-->
         //对于按钮,<!--根据表单form的method属性设置成post还是get提交;如果是post,则以

http://localhost:13409/TempCode/FormSubmit.aspx传送;如果是get方式,则以http://localhost:13409/TempCode/FormSubmit.aspx?

__VIEWSTATE=%2FwEPDwUJNzgzNDMwNTMzZGTPbywXbcRWoc86gvLdI5ybRPrUbg%3D%3D&Text=Hello+World&Text=Hello+World1方式传送;取到的值不

唯一,为Hello World,Hello World1-->
         //对于提交之后,获得的值,是将同名的值用逗号隔开的字符串

转载于:https://www.cnblogs.com/lushuicongsheng/archive/2010/11/12/1876084.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值