您的位置:首页 > 产品设计 > UI/UE

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>") ) );编码后解码,相当于两个都没有
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: