[ Team LiB ] |
Chapter 16. The HttpRequest ClassThe HttpRequest class is ASP.NET's replacement for ASP's Request intrinsic object. Because the HttpRequest class instance for a given ASP.NET page is exposed as the Request property of the Page class (from which all pages are derived), you can code to the HttpRequest class just as you did in ASP. Thus, your existing ASP code will be that much easier to migrate. The HttpRequest class is used to access information related to a particular HTTP request made by a web client. The HttpRequest class provides access to this information through its properties, collections, and methods. Each HTTP request from a client consists of an HTTP header and, optionally, a body. The header and body are separated by a blank line. The code following shows a typical HTTP request (without a body): GET /ASPdotNET_iaN/Chapter_16/showHTTP.aspx HTTP/1.0 Connection: Keep-Alive Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */* Accept-Charset: iso-8859-1,*,utf-8 Accept-Encoding: gzip Accept-Language: en Host: localhost User-Agent: Mozilla/4.08 [en] (WinNT; U ;Nav) The first line of the HTTP header contains the request type, followed by a space, followed by the requested URL (URI), another space, and the HTTP version number. In the previous example, the request type is GET, the URL is /ASPdotNET_iaN/Chapter_16/showHTTP.aspx (this URL is relative to the server or domain name), and the HTTP version is 1.0.
While we can gain much information from the text of an HTTP request header (which can be accessed either as a URL-encoded string in the Headers collection or by saving the request to disk by using the SaveAs method), having to parse the text each time we wanted to find a particular piece of information would be a pain. The HttpRequest class does this work for us, allowing us to deal only with the specific piece(s) of information that we're interested in. Table 16-1 lists the properties, collections, and methods exposed by the HttpRequest class.
|
[ Team LiB ] |