ASP Request Object

The Request object provides access to all the information that is passed in a request from the browser to the server. This information is stored among five types of Request collections. Individual items in the collection are accessed via a unique key assigned to that item.

Property

TotalBytes Property
Specifies the total number of bytes sent in the body of the HTTP request.

Collection

ClientCertificate Collection
Contains the values of the client certification fields of the request. Used in SSL protocols.

Cookies Collection
Contains the values of the cookies sent in the request.

Form Collection
Contains the values of the <FORM> elements posted to a form using the POST method.

QueryString Collection
Contains the values of the HTTP query string, which are the statements in the URL that follow a question (?) mark.

ServerVariables Collection
Contains the values of server environmental variables. This allows access to the HTTP headers.

Method

BinaryRead(Count) Method
Retrieves the data that was sent to the server from the browser as part of a POST request, and returns the number of bytes read.

Tips & Hints

Looping Through Collections
You can use VBScript's "For Each - Next" control statement to quickly loop through all of the items in a collection.

<%
  'looping through items of the Request.QueryString collection
  For Each i In Request.QueryString
    Response.Write i & " = " & Request.QueryString(i) & "<br>"
  Next
%>
For example, if your URL was:
http://www.everything2.com/index.pl?type=e2node&node=HTML
then the above code would result in:
  type = e2node
  node = HTML
This comes in handy when processing a form with dozens of inputs.

Request(variable) Shortcut
All variables can be accessed directly by calling Request(variable) without the collection name. In this case, the web server searches the collections in the following order:

  1. QueryString
  2. Form
  3. Cookies
  4. ClientCertificate
  5. ServerVariables
This is a time saving shortcut while coding, but you have to be careful if you have more then one variable of the same name.
For example:
-------my_page.asp------
<form method="post" action="save_page.asp?save=yes">
  <input type="text" name="save">
  <input type="submit" name="submitForm" value="Submit">
</form>

------save_page.asp------
<%
  Response.Write Request("save")
%>
This will write "yes", not what the user typed in the form's text input field.

Optimizing Performance - Request(variable) vs. Request.Collection(variable)
A pitfall of using Request(variable) is that it takes the server longer to locate the item then if you use the fully qualified name, since the server has to sequentially search each collection for the item. While this is probably not going to make a difference on your personal web page, heavily loaded servers would notice a significant increase in efficiency by using the fully qualified name.


Back to ASP Objects


Resources:
http://www.devguru.com/
http://msdn.microsoft.com/

All code is my own (and may cause premature balding).

(v 3.0) indicates that this feature is only available with ASP Version 3.0, which shipped standard with IIS 5.0