ASP Hosting sale!
1,000MB space, 40GB transfer, 1 SQL Server 2000 db! - $9.95 per month*!
Limited Time Offer!

aspdev | articles | tutorials | forums

ASPdev -> ASP Tutorial -> ASP Request

ASP Request

The ASP Request object is used to retrieve the values sent by the client browser to the server in an HTTP request.

The ASP Request object has several collections, methods and properties and I’ll demonstrate how to use them.

The ASP Request object has only one method - Request.BinaryRead. The Request.BinaryRead method retrieves the data POSTed (submitted with POST HTTP request) to the server from the user’s browser.

Request.Cookies collection – The Request.Cookies collection allows to retrieve the values of cookies sent with the HTTP request.

Cookies are transmitted as clear text, that’s why it’s not recommended to store sensitive information in cookies.

The example below shows how to retrieve and print the value of a cookie called TheCookie:

Response.Write Request.Cookies("TheCookie")

Request.Form collection – The Request.Form collection allows to retrieve the values of an HTML form elements submitted with the POST HTTP method.

Here is an example of Request.Form use:

Response.Write Request.Form(“Username”)

Request.QueryString collection – The Request.QueryString collection allows to retrieve the values of an HTML form elements submitted with the GET HTTP method.

The query string is the part of the URL after the question mark. For example the following URL will generate a GET request:

You can retrieve the value of pageID in your ASP page, by using the following code:

Response.Write Request.QueryString(“pageID”)

Request.ServerVariables collection contains information about the server where your ASP script is running on information about the client requesting the ASP script. The ServerVariables collection can give you lots of information about the server settings – Server IP, Server name, Server virtual path, Server Software (IIS4, IIS5 or IIS6), etc. Using ServerVariables you can get your visitors’ IP address, their browser version, their browser language settings, etc.

The list of ServerVariables depends on the server software (IIS version) and on the browser being used. The ASP script below will return a list of all ServerVariables available on your server, when you request this page in your browser:

For Each Item In Request.ServerVariables
Response.Write Item & " = " & Request.ServerVariables(Item) & "<br>"

Here is a sample list of some of the Request.ServerVariables collection members:

REMOTE_ADDR - The IP address of the remote host making the request.
REMOTE_HOST - The name of the host making the request.
REQUEST_METHOD - The method used to make the request. For HTTP, this might be GET, HEAD, POST, etc.
SCRIPT_NAME - A virtual path to the script being executed.
SERVER_NAME - The server's host name or IP address
SERVER_PORT - The port number to which the request was sent.

Contact Us