ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别
2010-12-23 17:14
956 查看
表单form的提交有两种方式,一种是get的方法,一种是post 的方法.看下面代码,理解ASP.NET Get和Post两种提交的区别:
代码
表单提交中,ASP.NET的Get和Post方式的区别归纳如下几点:
1. get是从服务器上获取数据,post是向服务器传送数据。
2. get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到。post是通过HTTP post机制,将表单内各个字段与其内容放置在HTML HEADER内一起传送到ACTION属性所指的URL地址。用户看不到这个过程。
3. 对于get方式,服务器端用Request.QueryString获取变量的值,对于post方式,服务器端用Request.Form获取提交的数据。
4. get传送的数据量较小,不能大于2KB。post传送的数据量较大,一般被默认为不受限制。但理论上,IIS4中最大量为80KB,IIS5中为100KB。
5. get安全性非常低,post安全性较高。但是执行效率却比Post方法好。
建议:
1、get方式的安全性较Post方式要差些,包含机密信息的话,建议用Post数据提交方式;
2、在做数据查询时,建议用Get方式;而在做数据添加、修改或删除时,建议用Post方式。
params、Request、Request.querystring、Request.Form 具体区别!
MSDN:Request ObjectRequest
Request.Form:获取以POST方式提交的数据(接收Form提交来的数据);
Request.QueryString:获取地址栏参数(以GET方式提交的数据)
Request:包含以上两种方式(优先获取GET方式提交的数据),它会在QueryString、Form、ServerVariable中都按先后顺序搜寻一遍。而且有时候也会得到不同的结果。如果你仅仅是需要Form中的一个数据,但是你使用了Request而不是Request.Form,那么程序将在QueryString、ServerVariable中也搜寻一遍。如果正好你的QueryString或者ServerVariable里面也有同名的项,你得到的就不是你原本想要的值了。
Request.Params是所有post和get传过来的值的集合,request.params其实是一个集合,它依次包括request.QueryString、request.Form、request.cookies和request.ServerVariable。
asp.net 默認虽然是POST Form,但是只是自己post自己,不能POST到其他页面
如果非要提交到令一个页面的话 用HTML元素 把runat="server" 去掉 用submit提交
用Request.Form["xxx"] 可以取值
代码
view plaincopy to clipboardprint? < form id="form1" method="get" runat="server"> < div> 你的名字< asp:TextBox ID="name" runat="server">< /asp:TextBox>< br /> < br /> 你的网站< asp:TextBox ID="website" runat="server">< /asp:TextBox>< br /> < br /> < br /> < asp:Button ID="Button1" runat="server" Text="send" />< br /> < br /> < br /> 学习request 和 response的用法< br /> < br /> < br /> < /div> < /form> < form id="form2" method="post" runat="server"> < div> 你的名字< asp:TextBox ID="name2" runat="server">< /asp:TextBox>< br /> < br /> 你的网站< asp:TextBox ID="website2" runat="server">< /asp:TextBox>< br /> < br /> < br /> < asp:Button ID="Button2" runat="server" Text="send" />< br /> < br /> < br /> 学习request 和 response的用法< br /> < br /> < br /> < /div> < /form> /*从URL中可看出ASP.NET Get和Post的区别.那么那如何编程实现数据的接收呢? 第1种,接收用get 方法传输的数据的写法: */ protected void Page_Load(object sender, EventArgs e) { string id = Request.QueryString["name"]; string website = Request.QueryString["website"]; Response.Write(id + "< br>" + website); Response.Write("你使用的是" + Request.RequestType + "方式传送数据"); } //第2种,接收用post 方法传输的数据的写法: protected void Page_Load(object sender, EventArgs e) { string id2 = Request.Form["name2"]; string website2 = Request.Form["website2"]; Response.Write(id2 + "< br>" + website2); Response.Write("你使用的是" + Request.RequestType + "方式传送数据"); } string id4 = Request["name4"]; string website4 = Request["website4"]; Response.Write(id4 + "< br>" + website4); //第3种,同时接受get和post 方法传送数据的代码写法: //A 写法 string id3 = Request.Params["name3"]; string website3 = Request.Params["website3"]; Response.Write(id3 + "< br>" + website3); //B 写法 string id4 = Request["name4"]; string website4 = Request["website4"]; Response.Write(id4 + "< br>" + website4);
表单提交中,ASP.NET的Get和Post方式的区别归纳如下几点:
1. get是从服务器上获取数据,post是向服务器传送数据。
2. get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到。post是通过HTTP post机制,将表单内各个字段与其内容放置在HTML HEADER内一起传送到ACTION属性所指的URL地址。用户看不到这个过程。
3. 对于get方式,服务器端用Request.QueryString获取变量的值,对于post方式,服务器端用Request.Form获取提交的数据。
4. get传送的数据量较小,不能大于2KB。post传送的数据量较大,一般被默认为不受限制。但理论上,IIS4中最大量为80KB,IIS5中为100KB。
5. get安全性非常低,post安全性较高。但是执行效率却比Post方法好。
建议:
1、get方式的安全性较Post方式要差些,包含机密信息的话,建议用Post数据提交方式;
2、在做数据查询时,建议用Get方式;而在做数据添加、修改或删除时,建议用Post方式。
params、Request、Request.querystring、Request.Form 具体区别!
MSDN:Request ObjectRequest
Request.Form:获取以POST方式提交的数据(接收Form提交来的数据);
Request.QueryString:获取地址栏参数(以GET方式提交的数据)
Request:包含以上两种方式(优先获取GET方式提交的数据),它会在QueryString、Form、ServerVariable中都按先后顺序搜寻一遍。而且有时候也会得到不同的结果。如果你仅仅是需要Form中的一个数据,但是你使用了Request而不是Request.Form,那么程序将在QueryString、ServerVariable中也搜寻一遍。如果正好你的QueryString或者ServerVariable里面也有同名的项,你得到的就不是你原本想要的值了。
Request.Params是所有post和get传过来的值的集合,request.params其实是一个集合,它依次包括request.QueryString、request.Form、request.cookies和request.ServerVariable。
asp.net 默認虽然是POST Form,但是只是自己post自己,不能POST到其他页面
如果非要提交到令一个页面的话 用HTML元素 把runat="server" 去掉 用submit提交
用Request.Form["xxx"] 可以取值
相关文章推荐
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别 [转]
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别 [转]
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别 [转]
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别 [转]
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别 [转]
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别 [转]
- ASP.NET中Get和Post的用法 Request.QueryString,Request.Form,Request.Params的区别 [转]
- ASP.NET-->>Get和Post的接收参数:Request.QueryString,Request.Form,Request.Params异同
- asp.net Request.Form Request.para Request.Querystring 区别
- ASP.NET 以 Request.Querystring、Request.Form 或 Request.Params 获取客户端的数据
- ASP.NET 以 Request.Querystring、Request.Form 或 Request.Params 获取客户端的数据
- ASP.NET 以 Request.Querystring、Request.Form 或 Request.Params 获取客户端的数据
- asp.net Request、Request.Form、Request.QueryString的区别(转)
- post提交方式,get提交方式,context.Request.QueryString["key"],context.Request.Form["key"],context.Request.Params["key"],context.Request.["key"]