HttpRequest 类
关于此类的介绍:查看HttpRequest类
点击查看:HttpRequest中方法的封装
跟这个类对应的HttpResponse类
定义:使 ASP.NET 能够读取客户端在 Web 请求期间发送的 HTTP 值。
public sealed class HttpRequest
注:本篇主要介绍可以根据这个类获取什么信息,只会介绍一些用到的方法。
你先要在引用中添加 System.Web.然后引用命名空间。
属性:
int loop1, loop2; NameValueCollection coll; // Load Header collection into NameValueCollection object. coll = Request.Headers; // Put the names of all keys into a string array. String[] arr1 = coll.AllKeys; for (loop1 = 0; loop1 < arr1.Length; loop1++) { Response.Write("Key: " + arr1[loop1] + "<br>"); // Get all values under this key. String[] arr2 = coll.GetValues(arr1[loop1]); for (loop2 = 0; loop2 < arr2.Length; loop2++) { Response.Write("Value " + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br>"); } } }
HttpRequestC.WriteCookie("two", "li", "Name"); HttpRequestC.WriteCookie("two", "187", "Age");
Response.Write(HttpRequestC.GetCookie("one")+"<br>"); Response.Write(HttpRequestC.GetCookie("two","Name") + "<br>"); Response.Write(HttpRequestC.GetCookie("two", "Age") + "<br>");
Request.Params["xxx"];//通用方法



HttpFileCollection.Item 属性 (String)

HttpPostedFile 类
提供已上载的客户端的各个文件的访问权限。

<asp:FileUpload ID="fileUpload" runat="server" /> <asp:FileUpload ID="fileTwo" runat="server" />
protected void LinkButton1_Click(object sender, EventArgs e) { int loop1; HttpFileCollection Files = Request.Files; string[] arr1 = Files.AllKeys; for (loop1 = 0; loop1 < arr1.Length; loop1++) { Response.Write("File: " + Server.HtmlEncode(arr1[loop1]) + "<br />"); Response.Write(" size = " + Files[loop1].ContentLength + "<br />"); Response.Write(" content type = " + Files[loop1].ContentType + "<br />"); } HttpPostedFile pf = Request.Files["fileTwo"]; Response.Write("Name:"+pf.FileName+"<br>"); Response.Write("流对象:"+pf.InputStream + "<br>"); Response.Write("字节:"+pf.ContentLength + "<br>"); Response.Write("类型:"+pf.ContentType + "<br&gwww.easck.comt;"); }
基本介绍就到这了。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。








