• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Welcome to Leon's Blog
博客园    首页    新随笔    联系   管理    订阅  订阅

Request类和Response类

来源:http://www.cnblogs.com/aidd2008/archive/2009/02/02/1382556.html

 

 

对象
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>") ) );编码后解码,相当于两个都没有

posted @ 2009-03-27 22:08  Leon916  阅读(633)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3