C# 之 HttpRequest 类

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

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

      filename与请求关联的文件的名称 ;url有关当前请求的 URL 的信息;q ueryString与请求一起发送的整个查询字符串('?' 之后的所有内容)。 属性:
名称用法说明
AcceptTypesString[] arr = Request.AcceptTypes;获取客户端支持的 MIME 接受类型的字符串数组。
AnonymousIDRequest.AnonymousID获取该用户的匿名标识符(如果存在)。
ApplicationPathRequest.ApplicationPath获取服务器上 ASP.NET 应用程序的虚拟应用程序根路径。
AppRelativeCurrentExecutionFilePathRequest.AppRelativeCurrentExecutionFilePath获取应用程序根的虚拟路径,并通过对应用程序根使用波形符 (~) 表示法(例如,以“~/page.aspx”的形式)使该路径成为相对路径。
BrowserRequest.Browser获取或设置有关正在请求的客户端的浏览器功能的信息。
ClientCertificateRequest.ClientCertificate获取当前请求的客户端安全证书。
ContentEncodingString EncodingType;
EncodingType = Request.ContentEncoding.EncodingName;
获取或设置实体主体的字符集。
ContentLengthRequest.ContentLength指定客户端发送的内容长度(以字节计)。
ContentTypeString str;
str = Request.ContentType;
获取或设置传入请求的 MIME 内容类型。
CookiesHttpCookie MyCookie;
MyCookieColl = Request.Cookies;
获取客户端发送的 Cookie 的集合。
CurrentExecutionFilePathsw.WriteLine(Server.HtmlEncode(Request.CurrentExecutionFilePath));获取当前请求的虚拟路径。
CurrentExecutionFilePathExtensionRequest。CurrentExecutionFilePathExtension获取 CurrentExecutionFilePath 属性中指定的文件名的扩展名。
FilePathRequest.FilePath获取当前请求的虚拟路径。
FilesHttpFileCollection Files = Request.Files;获取采用多部分 MIME 格式的由客户端上载的文件的集合。
FilterRequest.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 对象。
HttpMethodsw.WriteLine(Server.HtmlEncode(Request.HttpMethod));获取客户端使用的 HTTP 数据传输方法(如 GET、POST 或 HEAD)。
InputStreamSystem.IO.Stream str = Request.InputStream;获取传入的 HTTP 实体主体的内容。
IsAuthenticatedRequest.IsAuthenticated获取一个值(true or false),该值指示是否验证了请求。
IsLocalRequest.IsLocal获取一个值(true or false),该值指示是否来自本地计算机。
IsSecureConnectionRequest.IsSecureConnection获取一个值(true or false),指示 HTTP 连接是否使用安全套接字(即 HTTPS)。
Item QueryStringFormCookiesServerVariables 集合获取指定的对象。
LogonUserIdentityif (!Request.LogonUserIdentity.IsAuthenticated)
            Response.Redirect("LoginPage.aspx");
获取当前用户的 WindowsIdentity 类型。
ParamsNameValueCollection pColl = Request.Params;获取 QueryStringFormCookiesServerVariables 项的组合集合。
PathRequest.Path获取当前请求的虚拟路径。
PathInfosw.WriteLine(Server.HtmlEncode(Request.PathInfo));获取具有 URL 扩展名的资源的附加路径信息。
PhysicalApplicationPathsw.WriteLine(Server.HtmlEncode(Request.PhysicalApplicationPath));获取当前正在执行的服务器应用程序的根目录的物理文件系统路径
PhysicalPathsw.WriteLine(Server.HtmlEncode(Request.PhysicalPath));获取与请求的 URL 相对应的物理文件系统路径。
QueryStringstring fullname1 = Request.QueryString["fullname"];
string fullname2 = Request["fullname"];
获取 HTTP 查询字符串变量集合。
RawUrlRequest.RawUrl获取当前请求的原始 URL。
ReadEntityBodyMode 获取指示请求实体是否被读以及如何被读的值。
RequestContext 获取当前请求的 RequestContext 实例。
RequestTypesw.WriteLine(Server.HtmlEncode(Request.RequestType));获取或设置客户端使用的 HTTP 数据传输方法(GET 或 POST)。
ServerVariablesNameValueCollection coll = Request.ServerVariables;
String[] arr1 = coll.AllKeys;
获取 Web 服务器变量的集合。
TimedOutToken 获取请求超时时去除的 CancellationToken 对象。
TotalBytesRequest.TotalBytes获取当前输入流中的字节数
Unvalidated 提供对 HTTP 请求值的访问权限,不触发请求验证。
UrlUri MyUrl = Request.Url;获取有关当前请求的 URL 的信息。
UrlReferrerUri MyUrl = Request.UrlReferrer;获取有关客户端上次请求的 URL 的信息,该请求链接到当前的 URL。
UserAgentString userAgent = Request.UserAgent;获取客户端浏览器的原始用户代理信息。
UserHostAddresssw.WriteLine(Server.HtmlEncode(Request.UserHostAddress));获取远程客户端的 IP 主机地址。
UserHostNamesw.WriteLine(Server.HtmlEncode(Request.UserHostName));获取远程客户端的 DNS 名称。
UserLanguagesString[] userLang = Request.UserLanguages;获取客户端语言首选项的排序字符串数组。

方法:

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

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

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

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值