request|response| Objects | built-in objects | Internal objects request and response these two objects are the most commonly used two of the built-in objects provided by ASP. Between browsers (or other user agents) and Web servers, the exchange of information that occurs in requests and responses can be accessed and managed through two built-in objects in the ASP, called the request and response objects.
Almost all of the work you want to do in an ASP page is to access both objects, and the way you use them affects the efficiency and reliability of your pages. Their main purpose, of course, is to access the values that users send back to the server, either from the <FORM> segment of the HTML page or as a query string after the URL, and to create the appropriate output to return to the user, and they can share many of the same factors. For example, two objects can use cookies that are stored on the client computer.
Therefore, we divide the content into two separate parts (each part of the object), and start with the information exchange between the client and the server, and then study each object.
The contents of the study are:
· How the client communicates with the server to deliver the Web or other resources.
· The details of the request and response objects, and the similarities between them.
· How to access the corresponding value through a form and query string.
· How to read or create cookies and store them on the client computer.
· What are the server variables? How to access and modify the HTTP header.
· Describe changes to other related items, such as the use of the customer's certificate.
communication between the client and the server
To save space, the term "browser" (browser) is used in the following context. But keep in mind that applications that can access Web pages are not just browsers, there are many special applications that download Web pages from sites, such as special client programs designed for visually impaired users or other difficulties with the usual browsers. The most obvious example is the robot that search engines use to access sites on the web. Consider these factors comprehensively, including a common web browser, and the exact words should be the user agent.
dialog for page requests
When a browser presents a page request to a Web site, it is clear that the server must be told which page it is requesting. The first thing to do is to establish a connection with the server through the domain name, and then provide the full path and name of the requested page. Why do I need full path and name? The web is a borderless environment, so you must create a session to identify each customer (how the ASP will do this later).
This means that every time the server completes sending a page to the customer, the server completely forgets about the customer. Therefore, when the customer requests the next page, it is exactly the same as a new visitor. The server is unable to remember the customer and, accordingly, cannot determine which page they last requested. Because you cannot use a relative path to provide a page, even if the page contains a relative link, for example:
<a Href= "download.asp" >next Page </A>
The browser automatically creates a complete URL for the new page by using the current page's domain and path, or by using the <BASE> element in the page <HEAD> section, telling the browser what the URL is for all links in a page. For example:
<base herf=http://www.wrox.com/store>
When you point the mouse at a link to a page, you can see it in the browser's status bar. The path to the current page and the current domain or base domain name or base path have been combined with the requested page name.
1, the customer request details
A combination of the full path and name of the requested page is the only place where the browser requests a page to be sent to the server. The browser's request can also contain the domicile of the browser host and the operating system that the client is running. The actual content of the information will change with the browser, and only a few can be provided by other applications such as search engine robot. To get a clearer picture of this information, here is a page http://www.wrox.com/Store/from IE 5.0
Download.asp Request Information:
7/8/99 10:27:16 Sent get/store/download.asp http/1.1
Accept:application/msword, Application/vnd.ms-execl, application/vnd.ms-
PowerPoint, Image/gif, Image/x-xbitmap, Image/jpeg, Image/pjpeg, application/x-
Comet, */*
Accept-language:en-us
Encoding:gzip, deflate
Referer:http://ww.wrox.com/main_menu.asp
Cookie:visitcount=2&lastdate=6%2f4%2f99+10%3a10%3a13+am
user-agent:mozilla/4.0 (compatible; MSIE 5.0; Windows 98)
host:212.250.238.67
Connection:keep-alive
As you can see, the information contains details about the user agent and user connections (such as the default language), as well as a list of the types of files or applications that can be accepted, all of which are MIME types and will be met later. Browsers can accept several image files and a variety of Microsoft Office file types. "Standard" file types, such as tesx/html and Text/text, are not listed therein. The */* in the file list indicates that any type of file can be sent back to the browser, interpreted by the browser, or explained by a plug-in (plug-in) application.
Cookie: The entry contains a cookie that is stored on the client computer and is valid only for that domain. If the request is the result of clicking on the link instead of entering the URL directly in the address bar of the browser, Referer: The entry is displayed and contains the full URL of the linked page.
Host: Entry contains the IP address or name of the client computer. However, this is not sufficient to accurately identify the client. Because the IP address is dynamically assigned when they are connected through the ISP, or when connected through a proxy server, the IP address is the agent rather than the actual client.
2, the server response details
To respond to the above request, and to provide the requested page for the Anonymous browser (that is, the user does not have to provide a username and access password), the following is sent from the server to the client:
7/8/99 10:27:16 Received http/1.1 OK
server:microsoft-iis/5.0
Connection:keep-alive
Date:thu, 8 June 1999 10:27:16 GMT
Content-type:text/html
Accept-ranges:bytes
content-length:2946
Last-modified:thu, 8 June 1999 10:27:16 GMT
Cookie:visitcount=3&lastdate=7%2f8%2f99+10%3a27%3a16+am
<HTML>
... rest of page ...
</HTML>
You can see the server to the client to explain their own software and version, the first line indicates that the HTTP protocol used, and return code status. Information "OK" indicates that the request was accepted and satisfied. The following information is the details of the returned page, including the MIME type (content-length:), size (bytes), last changed time, and the cookie that returns the client store. Other information in the response is the flow of content in the page.
In some cases, the server cannot return a page after responding to a request, perhaps because the page does not exist or the client does not have the appropriate permissions to access it. We'll discuss security issues later. Now, for situations where the request page does not exist (for example, the user has entered the wrong URL in the browser's address bar), the information returned begins with:
7/8/99 14:27:16 Received http/1.1 404 Not Found
server:microsoft-iis/5.0
...
Here, the status code and information indicate that the page requested by the customer cannot be found. The browser can use this information to display to the user the appropriate information (this situation in IE 5.0 does not display the server's response information, and display the appropriate "Help" Error prompt page), you can also display the server created default page (depending on the server settings). Request and Response objects
The details of the ability to apply customer requests and server responses from an ASP are implemented through the ASP's built-in request and response objects.
· Request object: Provides the script with all the information the client provides when the client requests a page or passes a form. This includes an HTTP variable that indicates the browser and the user, a cookie stored in the browser under the domain name, and any value of the HTML control in the string or the
segment of the page that is appended to the URL as a query string. Also provides authorization access using secure Socket Layer (SSL) or other cryptographic communication protocols, and properties that help manage the connection.
· Response object: Used to access concurrent back created by the server side
[1] [2] Next page