These two objects are the two most commonly used built -in objects provided by ASP. Between the browser (or other user agents) and the web server, the information exchange between the request and the response can be accessed and managed through the two built -in objects in the ASP. These two objects are called Request and Response objects.
Almost all the work to be performed on the ASP page must access these two objects. The method of using these two objects will affect the efficiency and reliability of the page. Of course, their main use is to access the value of the user sent back to the server, that is, obtained or attached to the URL as a query string from the <FORM> paragraph of the HTML page, and create a suitable output to return it to the user, and they can share a lot of a lot The same factor. For example, both objects can use cookies stored on the client computer.
Communication of clients and servers
To save space, the word "browser" is used in the following content. But what needs to be remembered is that applications that can access the web page are not only browsers. There are many special applications to download web pages from the site, such as special client programs designed for those who are defective users, or usually use it. There are other people with other difficulties in the browser. The most obvious example is that search engines are used to access the Robot of the site on Web. Throughout these factors, including ordinary web browsers, accurate vocabulary should be user agents.
Page request dialogue
When a browser makes a page request to the web site, it is clear that the server must be told to which page it requests. 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 required page. Why do you want the full path and name? Web is a borderless environment, so it must create a session logo every customer.
This means that whenever the server is sent to the customer, the server completely forgets the customer. Therefore, when the customer requests the next page, it is exactly the same as a new visitor. The server cannot remember this customer. Correspondingly, it is impossible to judge which one they requested last time. Because, the relative path cannot be used to provide a page, even if the page contains a relative link, it will not work, for example::
<Ahref = "doubled.asp"> NextPage </a>
The browser will automatically build a complete new page URL to use the domain and path of the current page; or use the <base> element in the <head> paragraph to tell the browser what the URL of all links in the browser. For example:
<Baseherf = http://www.wrox.com/store>
When you point the mouse to the link of a page, you can see in the status bar of the browser. The path of the current page and the current domain name or base or base path are already combined with the request page name.
1. Details of customer requests
The combination of the entire path and name of the request page is the only residence of the browser who sends the server when the browser request page is requested by the browser request page. The actual information content will change accordingly with the different browsers, only a few can be provided by other applications such as search engine ROBOT. In order to understand the information more clearly, the following is a pair page from IE5.0 to page http://www.wrox.com/store/
Download.asp request information:
7/8/9910: 27: 16SENTGET/Store/DOWNLOAD.ASPHTTP/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%3A13+AM
User-agent: mozilla/4.0 (compatible; msie5.0; Windows98)
Host: 212.250.238.67
Connection: kep-alive
It can be seen from this that this information is about the details of the user agent and the user connection (such as the default language), and there are types of types of files or applications that can be acceptable. These are MIME types. many. The browser can accept several image files and a variety of MicrosoftOffice file types. The "standard" file type, such as TESX/HTML and Text/Text, are not listed in it. In the file list,*/*indicates that it can be sent back to the browser to send any type of file, which is explained by the browser or explained through a plug-in application.
Cookie: Cookie contained in the entry is stored on the client's computer and is only valid for the domain. If the request is the result of clicking the link instead of entering the URL directly in the browser's address bar, then Referrs: The entry is displayed, it contains the complete URL of the link page.
Host: The entry contains the IP address or name of the customer computer. However, this is not enough to accurately distinguish the client. Because when they are connected through ISP, the IP address is dynamically allocated, or when a proxy server is connected, the IP address is a proxy machine rather than the actual client.
2. Details information for server response
In response to the above requests, and the page provided the request for anonymous browser (that is, users do not need to provide user names and access passwords), the following content is sent from the server to the client:
7/8/9910: 27: 16Receivedttp/1.1200OK
Server: Microsoft-IIS/5.0
Connection: kep-alive
Date: THU, 8Jul199910: 27: 16GMT
Content-Type: Text/HTML
Accept-ranges: bytes
Content-specific: 2946
Last-Modify: T, 8Jul199910: 27: 16GMT
Cookie: Visitcount = 3 & LastDate = 7%2F8%2F99+10%3A27%3A16+AM
<Html>
… Restofpage ...
</Html>
It can be seen that the server explains the software and versions you use to the client. The first line indicates that the HTTP protocol and the status of the return code are used. The information "200OK" means that the request is accepted and satisfied. The later information is the details of the returned page, including the MIME type-specific :), size (byte), recent changes, and cookies stored in the client. Other information in the response is the information flow of the page content.
In some cases, after the server responds to a request, it cannot return a page. Perhaps because the page does not exist, or customers do not have corresponding permissions to access it. We will discuss security issues later. Now, for the situation where the request page does not exist (for example, the user has entered the wrong URL in the browser's address bar), and the information returned is:
7/8/9914: 27: 16Receivedtp/1.1404notfound
Server: Microsoft-IIS/5.0
Mowing
Here, the status code and information indicate that the pages of the customer's request cannot be found. The browser can use this information to display the corresponding information to the user (this situation does not display the response information of the server in IE5.0, and the corresponding "help sex" error prompt page is displayed), and the default page created by the server can also display the server created. (Depending on the settings of the server).
Request and Response objects
The details that can apply customer requests and server response from ASP are achieved by ASP built -in Request and Response objects.
· Request Object: Provide a script with all information provided by the client when the client requests a page or pass a window. This includes the HTTP variable that can indicate the browser and user, and the cookie placed in the browser under this domain name, any string that is attached to the <Form> section of the <Form> section behind the URL as a query string, Essence It also provides authorized access to the use of SecureSocketLayer (SSL) or other encrypted communication protocols, and it helps to manage the connection.
· Response object: Used to access the concurrent response information created by the server side. Provide HTTP variables for scripts, indicating the functions of the server and server, and information about the content of the browser, and any new cookie that will be stored in the browser for this domain. It also provides a series of methods to create output, such as the ubiquitous response.write method.
<H3> Overview of members of the Request object </h3>
A collection of a request object
grammar:
Response.Collection | Property | Method
The Request object provides 5 sets to access the client's various information requested by the web server.
Clientcertified
When the client accesss one page or other resources, the numerical collection of all fields or entries used to show the customer's customer certificate to the server, each member only reads
Cookies
According to the user's request, the collection of all Cookie values issued by the user system, these cookies are only effective for the corresponding domain, each member is read only
Form
When the attribute value of Method is post, all members of the <Form> section of the <Form> paragraph as requested, each member is read only
Querystring
The name/value pair behind the URL required by the user or the METHOD attributes submitted as a request are GET (or omitted its attributes), or the value of all HTML control units in <FORM>, each member is read only by reading only
Servervariables
With the http header value issued with the client request, and the collection of the values of several environment variables of the web server, each member is read only
The attribute of the two Request object
The only attributes and descriptions of the Request object are as shown in the table below. It provides information on the number of bytes required by the user. It is rarely used for the ASP page. We usually pay attention to the specified value instead of the entire request string.
Totlbytes
Read only, return the entire number of bytes requested by the client
Method of the Three Request objects
The only method and instructions of the Request object are as shown in the table below.
BinaryRead (count)
When the data is sent to the server as a part of the POST request, the data of the count byte is obtained from the customer's request, and a Variant array (or Safearray) is returned. If the ASP code has quoted the Request.form set, this method cannot be used. At the same time, if you use the binaryRead method, you cannot access the request.form collection
<H3> Response Objects Overview </h3>
grammar:
Response.Collection | Property | Method
1. Collection
The response object has only one collection-cookies, and the cookies data set allows setting the data to the client's browser. Create it if the specified cookie does not exist. If you exist, update the data automatically.
Grammar: Response.cookies (Cookie) [Key.attribute]
The cookie here is the name of specified cookies. And if the key is specified, the cookie is a dictionary. Attribute specifies the relevant information about cookies itself. Attribute parameters can be one of the following:
Domain is only written. If it is specified, cookie will be sent to the request for the domain.
Expires only write. Specify the expiration date of Cookie. In order to store cookies on the client disk after the session is over, the date must be set. If the setting of this attribute does not exceed the current date, the cookie will expire after the task is over.
Haskeys only read. Specify whether the cookie contains keywords.
Path is only written. If it is specified, cookie will only send it to the request for the path. If the attribute is not set, the path of the application is used.
Secure is only written. Specify whether cookies are safe.
2. Method
Response.addheaderName, value
Add a new HTML title to the answer. Name is the name of the new HTML title. Value is the value of the head variable. You can add any HTML title with any name and any value. It does not replace the existing title of the same name. Once the title is added, it will not be deleted.
Response.appendtologstring
Add a string to the web server's log bar. String is a string to be added to the log file.
Response.binarywriteddata
This method can write the formal information to the HTTP output without any character conversion, which is mainly used to write non -string information (such as binary data required by client applications, etc.). Data is the data to be sent.
Response.clear
Delete all HTML outputs in the buffer, but only delete the response text without deleting the response title. You can use this method to deal with errors. It should be noted that if response.buffer is set to true, the method will cause operation to be wrong.
Response.end
Forced the web server to stop performing more scripts and send the current results, the remaining content in the file will not be processed. If response.buffer is set to true, calling response.end will buffer output.
Response.flush
For a cushioned response, send all the buffer information. If response.buffer is set to true, the method will cause operation to be wrong.
Response.redirecturl
Reduce the client's browser to a new Internet address. URL is the internet address of the new webpage.
Response.writevariant
Response.write is the most commonly used method for the Response object. This method can send a string to the browser. Variant is a string or a variable with a string value.
Three, attributes
Response.buffer
Cushion a ActiveServerPage. The response is only sent to the end of a certain page or response.flush or the response.end method. After the server is sent to the client, the buffer attribute cannot be set.
Response.cachecontrol
Indicate whether the Proxy server can cache ActiveServerPage. When the default is, its value is false. When setting its attribute to Public, the Proxy server can buffer the output generated by ASP.
Response.charset (charsetName)
Attach the character set name (such as GB) to the response object behind the CONTENT-TYPE title, and use it to set the web server to respond to the file character code to the client. A possible value is "ISO_LATIN_1".
Response.contenttype
Indicate the type of response content. The possible values are Text/PLAIN and Image/GIF, and the default value Text/HTML.
Response.expires
The browser can cache the time length of the current page, in minutes.
Response.expiresabsolute
The browser cannot cache the date and time of the current page. It can be returned before it expires. If the time is not specified, the homepage expires at midnight on the same day; if the date is not specified, the specified time will expire that day.
True/false = response.isClientConnect
The attribute is read -only, indicating whether the client is still connected to the server since the last call of response.write. This attribute allows users to have more control without connecting clients and servers. For example, when the request to make a request from the client should correspond to the server, and it is necessary to use it for a long time, this may help ensure that the client is still connected before continuing to handle the script. Has valuable True or False.
Response.pics (PICS string)
PICS level for adding web pages. PICS levels indicate the content level of a webpage, such as the degree of violence or pornography.
Response.status = Status description string
It is used to set the value of the state of the web server to respond.