Request类和Response类(转载)
2015-11-17 16:01
645 查看
对象
Request派生自HttpRequest类,从客户端获取信息,浏览器的种类,用户输入表单的数据,Cookies,客户端认证等
对应的Response.Write 负责处理前者获取的东西
表单提交
get
...?xxx=value&yyy=value
post
浏览器请求的HTTP标头中返回服务器
get
string id = Request.QuerryString["name"];
string age = Request.QuerryString["age"];
post
string id = Request.Form["name"];
string age = Request.Form["age"];
Request.Params["name"];//自己查提交方式
Request.Params["age"];
Request["name"];
Request["age"];
Response.Write(Request.RequestType );//传数据的方式
网页虚拟路径 Request.ServerVariables["url"]
Request.RawUrl
实际路径 Request.ServerVariables["path_translated"]
Request.PhysicalPath
服务器名 Request.ServerVariables["server_name"]
服务器IP Request.UserHostAddress
浏览器是否支持背景音乐 Request.Browser.BackgroundSounds
浏览器是否支持框架 Request.Browser.Frames
浏览器什么系统 Request.Browser.Platform
HttpCookie nc = new HttpCookie("newcookie");
nc.Values["name"] = "aidd";
nc.Values["age"] = "22";
nc.Values["dt"] = DataTime.Now.ToString();
HttpCookie getcook = Request.Cookies["newcookie"];
Response.Write(getcook.Values["age"]);
Response来自HTTPResponse类,回应客户端,告诉浏览器回应内容的报头,服务器端的信息以及输出指定的内容
ContentType描述内容类型的字符串,格式type/subtype,内容分类,特定内容类型。
默认 text/html
Response.ContentType = "image/gif";
Response.Clear();//删除缓冲区里的HTML输出,只删除预备输出的那些,并不删除Response头信息
Response.ClearHeaders();只头
Response.ClearContent();全部删除
Response.Expires = 5; 页面过期时间5分钟,重新下载,分钟
Response.ExpiresAbsolute = DateTime.Now.AddHours(8); 为了兼容asp,设置缓存移出的绝对时间,当前时间加8小时,后面是一个时间格式的。
不指定,则在午夜over
Response.Buffer = false; 页面是否缓冲输出,默认true
Response.Flush();立即缓冲输出
Response.End();立即输出,并停止当前页的执行,下面的不要了
Response.Redirect(http://aidd2008.cnblogs.com);重定向
String aa = Server.MapPath("~/app_data/a.xml").ToString() ;
Response.WriteFile(aa );
Response.Write( Server.HtmlDecode( Server.HtmlEncode("<script>alert('去过了吗?')</script>") ) );编码后解码,相当于两个都没有
Request派生自HttpRequest类,从客户端获取信息,浏览器的种类,用户输入表单的数据,Cookies,客户端认证等
对应的Response.Write 负责处理前者获取的东西
表单提交
get
...?xxx=value&yyy=value
post
浏览器请求的HTTP标头中返回服务器
get
string id = Request.QuerryString["name"];
string age = Request.QuerryString["age"];
post
string id = Request.Form["name"];
string age = Request.Form["age"];
Request.Params["name"];//自己查提交方式
Request.Params["age"];
Request["name"];
Request["age"];
Response.Write(Request.RequestType );//传数据的方式
网页虚拟路径 Request.ServerVariables["url"]
Request.RawUrl
实际路径 Request.ServerVariables["path_translated"]
Request.PhysicalPath
服务器名 Request.ServerVariables["server_name"]
服务器IP Request.UserHostAddress
浏览器是否支持背景音乐 Request.Browser.BackgroundSounds
浏览器是否支持框架 Request.Browser.Frames
浏览器什么系统 Request.Browser.Platform
HttpCookie nc = new HttpCookie("newcookie");
nc.Values["name"] = "aidd";
nc.Values["age"] = "22";
nc.Values["dt"] = DataTime.Now.ToString();
HttpCookie getcook = Request.Cookies["newcookie"];
Response.Write(getcook.Values["age"]);
Response来自HTTPResponse类,回应客户端,告诉浏览器回应内容的报头,服务器端的信息以及输出指定的内容
ContentType描述内容类型的字符串,格式type/subtype,内容分类,特定内容类型。
默认 text/html
Response.ContentType = "image/gif";
Response.Clear();//删除缓冲区里的HTML输出,只删除预备输出的那些,并不删除Response头信息
Response.ClearHeaders();只头
Response.ClearContent();全部删除
Response.Expires = 5; 页面过期时间5分钟,重新下载,分钟
Response.ExpiresAbsolute = DateTime.Now.AddHours(8); 为了兼容asp,设置缓存移出的绝对时间,当前时间加8小时,后面是一个时间格式的。
不指定,则在午夜over
Response.Buffer = false; 页面是否缓冲输出,默认true
Response.Flush();立即缓冲输出
Response.End();立即输出,并停止当前页的执行,下面的不要了
Response.Redirect(http://aidd2008.cnblogs.com);重定向
String aa = Server.MapPath("~/app_data/a.xml").ToString() ;
Response.WriteFile(aa );
Response.Write( Server.HtmlDecode( Server.HtmlEncode("<script>alert('去过了吗?')</script>") ) );编码后解码,相当于两个都没有
相关文章推荐
- priority_queue 优先队列使用方法
- RAII(Resource Acquisition Is Initialization资源获取即初始化 )思想
- 向 mysql 插入insert时 汉字 Incorrect string value 解决办法
- iOS开发笔记--UILabel的相关属性设置
- iOS9.0布局神器UIStackView
- RequireJS与SeaJS模块化加载示例
- Run-Time Check Failure #0,The value of ESP was not properly saved 错误解决
- IOS8以上的UIAlertView
- 【原创】Silverlight的ComboBox.SelectValue无法赋值
- java中stringBuilder的用法
- 封装的UITextField
- UICollectionView创建 xib
- How to Back up and restore SharePoint 2013 using a VSS requestor
- UVA 题目10401 Injured Queen Problem(DP)
- Android 应用程序窗体显示状态操作(requestWindowFeature()的应用)
- iOS CoreBluetooth 教程
- leetcode #63 Unique PathsII
- leetcode #62 Unique Paths
- @PathVariable和@RequestParam
- 用SpriteBuilder简化"耕牛遍地走"的动画效果(四)