zoukankan      html  css  js  c++  java
  • C# 之 HttpRequest 类

          Request对象派生自HttpRequest类,使 ASP.NET 能够读取客户端在 Web 请求期间发送的 HTTP 值,从客户端获取信息,浏览器的种类,用户输入表单的数据,Cookies,客户端认证等,对应的Response.Write 负责处理前者获取的东西。

          构造函数:public HttpRequest(string filename, string url, string queryString)

          filename与请求关联的文件的名称;url有关当前请求的 URL 的信息;queryString与请求一起发送的整个查询字符串('?' 之后的所有内容)。
    属性:
    名称 用法 说明
    AcceptTypes String[] arr = Request.AcceptTypes; 获取客户端支持的 MIME 接受类型的字符串数组。
    AnonymousID Request.AnonymousID 获取该用户的匿名标识符(如果存在)。
    ApplicationPath Request.ApplicationPath 获取服务器上 ASP.NET 应用程序的虚拟应用程序根路径。
    AppRelativeCurrentExecutionFilePath Request.AppRelativeCurrentExecutionFilePath 获取应用程序根的虚拟路径,并通过对应用程序根使用波形符 (~) 表示法(例如,以“~/page.aspx”的形式)使该路径成为相对路径。
    Browser Request.Browser 获取或设置有关正在请求的客户端的浏览器功能的信息。
    ClientCertificate Request.ClientCertificate 获取当前请求的客户端安全证书。
    ContentEncoding String EncodingType;
    EncodingType = Request.ContentEncoding.EncodingName;
    获取或设置实体主体的字符集。
    ContentLength Request.ContentLength 指定客户端发送的内容长度(以字节计)。
    ContentType String str;
    str = Request.ContentType;
    获取或设置传入请求的 MIME 内容类型。
    Cookies HttpCookie MyCookie;
    MyCookieColl = Request.Cookies;
    获取客户端发送的 Cookie 的集合。
    CurrentExecutionFilePath sw.WriteLine(Server.HtmlEncode(Request.CurrentExecutionFilePath)); 获取当前请求的虚拟路径。
    CurrentExecutionFilePathExtension Request。CurrentExecutionFilePathExtension 获取 CurrentExecutionFilePath 属性中指定的文件名的扩展名。
    FilePath Request.FilePath 获取当前请求的虚拟路径。
    Files HttpFileCollection Files = Request.Files; 获取采用多部分 MIME 格式的由客户端上载的文件的集合。
    Filter Request.Filter = new QQQ1(Request.Filter); 获取或设置在读取当前输入流时要使用的筛选器。
    Form

    NameValueCollection coll = Request.Form;

    String[] arr1 = coll.AllKeys;

     获取窗体变量集合。
    Headers

    NameValueCollection coll = Request.Headers;

    String[] arr1 = coll.AllKeys;

    获取 HTTP 头集合。
    HttpChannelBinding  
    获取当前 HttpWorkerRequest 实例的 ChannelBinding 对象。
    HttpMethod sw.WriteLine(Server.HtmlEncode(Request.HttpMethod)); 获取客户端使用的 HTTP 数据传输方法(如 GET、POST 或 HEAD)。
    InputStream System.IO.Stream str = Request.InputStream; 获取传入的 HTTP 实体主体的内容。
    IsAuthenticated Request.IsAuthenticated 获取一个值(true or false),该值指示是否验证了请求。
    IsLocal Request.IsLocal 获取一个值(true or false),该值指示是否来自本地计算机。
    IsSecureConnection Request.IsSecureConnection 获取一个值(true or false),指示 HTTP 连接是否使用安全套接字(即 HTTPS)。
    Item   QueryStringFormCookiesServerVariables 集合获取指定的对象。
    LogonUserIdentity if (!Request.LogonUserIdentity.IsAuthenticated)
                Response.Redirect("LoginPage.aspx");
    获取当前用户的 WindowsIdentity 类型。
    Params NameValueCollection pColl = Request.Params; 获取 QueryStringFormCookiesServerVariables 项的组合集合。
    Path Request.Path 获取当前请求的虚拟路径。
    PathInfo sw.WriteLine(Server.HtmlEncode(Request.PathInfo)); 获取具有 URL 扩展名的资源的附加路径信息。
    PhysicalApplicationPath sw.WriteLine(Server.HtmlEncode(Request.PhysicalApplicationPath)); 获取当前正在执行的服务器应用程序的根目录的物理文件系统路径
    PhysicalPath sw.WriteLine(Server.HtmlEncode(Request.PhysicalPath)); 获取与请求的 URL 相对应的物理文件系统路径。
    QueryString string fullname1 = Request.QueryString["fullname"];
    string fullname2 = Request["fullname"];
    获取 HTTP 查询字符串变量集合。
    RawUrl Request.RawUrl 获取当前请求的原始 URL。
    ReadEntityBodyMode   获取指示请求实体是否被读以及如何被读的值。
    RequestContext   获取当前请求的 RequestContext 实例。
    RequestType sw.WriteLine(Server.HtmlEncode(Request.RequestType)); 获取或设置客户端使用的 HTTP 数据传输方法(GET 或 POST)。
    ServerVariables NameValueCollection coll = Request.ServerVariables;
    String[] arr1 = coll.AllKeys;
    获取 Web 服务器变量的集合。
    TimedOutToken   获取请求超时时去除的 CancellationToken 对象。
    TotalBytes Request.TotalBytes 获取当前输入流中的字节数
    Unvalidated   提供对 HTTP 请求值的访问权限,不触发请求验证。
    Url Uri MyUrl = Request.Url; 获取有关当前请求的 URL 的信息。
    UrlReferrer Uri MyUrl = Request.UrlReferrer; 获取有关客户端上次请求的 URL 的信息,该请求链接到当前的 URL。
    UserAgent String userAgent = Request.UserAgent; 获取客户端浏览器的原始用户代理信息。
    UserHostAddress sw.WriteLine(Server.HtmlEncode(Request.UserHostAddress)); 获取远程客户端的 IP 主机地址。
    UserHostName sw.WriteLine(Server.HtmlEncode(Request.UserHostName)); 获取远程客户端的 DNS 名称。
    UserLanguages String[] userLang = Request.UserLanguages; 获取客户端语言首选项的排序字符串数组。

    方法:

    名称 用法 说明
    Abort Abort() 强制地终止基础 TCP 连接,会导致任何显著的 I/O 失败。
    BinaryRead public byte[] BinaryRead(int count) 执行对当前输入流进行指定字节数的二进制读取。
    Equals (Object) person1a.Equals(person1b));               确定指定的对象是否等于当前对象。
    GetBufferedInputStream public Stream GetBufferedInputStream() 获取一个 Stream 对象,该对象可用于读取传入的 HTTP 实体主体。
    GetBufferlessInputStream() public Stream GetBufferlessInputStream() 获取一个 Stream 对象,该对象可用于读取传入的 HTTP 实体主体。
    GetBufferlessInputStream  (Boolean) public Stream GetBufferlessInputStream(
    bool disableMaxRequestLength
    )

    获取能被用于读取正在到来的 HTTP 实体正文的 Stream 对象,

    同时随意地禁止设置在 MaxRequestLength 属性中的请求长度限制。

    GetHashCode public virtual int GetHashCode() 作为默认哈希函数。 (继承自 Object。)
    GetType Object.GetType() 获取当前实例的 Type。 (继承自 Object。)
    InsertEntityBody public void InsertEntityBody() 向 IIS 提供 HTTP 请求实体正文的副本。
    InsertEntityBody(byte[], int, int) public void InsertEntityBody(byte[] buffer, int offset, int count) 向 IIS 提供 HTTP 请求实体正文的副本以及有关请求实体对象的信息。
    MapImageCoordinates public int[] MapImageCoordinates(string imageFieldName) 将传入图像字段窗体参数映射为适当的 x 坐标值和 y 坐标值。
    MapPath(string) public string MapPath(string virtualPath) 将指定的虚拟路径映射到物理路径。
    MapPath(String, String, Boolean) public string MapPath(string virtualPath,string baseVirtualDir,bool allowCrossAppMapping) 将指定的虚拟路径映射到物理路径。
    MapRawImageCoordinates public double[] MapRawImageCoordinates(string imageFieldName) 将传入图像字段窗体参数映射为适当的 x 和 y 坐标值。
    SaveAs public void SaveAs(string filename,bool includeHeaders) 将 HTTP 请求保存到磁盘。
    ToString Object obj = new Object();
    Console.WriteLine(obj.ToString());
    返回表示当前对象的字符串。 (继承自 Object。)
    ValidateInput public void ValidateInput() 对通过 CookiesFormQueryString 属性访问的集合进行验证。

     

  • 相关阅读:
    【LCT维护基环内向树森林】BZOJ4764 弹飞大爷
    【LCT】BZOJ3091 城市旅行
    【LCT+主席树】BZOJ3514 Codechef MARCH14 GERALD07加强版
    【最大权闭合子图】bzoj4873 [Shoi2017]寿司餐厅
    【LCT】BZOJ2049 [SDOI2008]Cave 洞穴勘测
    【有上下界的网络流】ZOJ2341 Reactor Cooling(有上下界可行流)
    【费用流】BZOJ1061: [Noi2008]志愿者招募(这题超好)
    从输入url到页面加载的过程
    forEach和map的区别
    理解 JavaScript 对象原型、原型链如何工作、如何向 prototype 属性添加新的方法。
  • 原文地址:https://www.cnblogs.com/xinaixia/p/3958007.html
Copyright © 2011-2022 走看看