This section provides a tutorial example on how to use the 'request' object provided by the ASP programming interface to receive data from the client, the Web browser.
The request object is a very rich object. It contains everything the client sends to
the server:
QueryString: A read only collection object representing all the names and values
sent from the browser by the GET method.
Form: A read only collection object representing all names and values sent
from the browser by the POST method.
Cookies: A read only collection object representing all the cookies sent from
the browser.
ServerVariables: A read only collection object representing all the names
and values in the HTTP request header and in the server environment.
TotalBytes: A read only property indicating the total number of bytes in this request.
BinaryRead(): A method to read all names and values sent from the browser by
the POST method.
The following ASP page shows how to access the property and collections of the request
object.
<script language="vbscript" runat="server">
' request_test.asp
' Copyright (c) 2002 by Dr. Herong Yang
' This program shows how to use the "request" object.
'
response.write("<html><body>")
response.write("<b>Tests on the request object</b>:<br/>")
response.write("Total bytes = " & request.TotalBytes & "<br/>")
set c = request.QueryString
response.write("QueryString.Count = " & c.Count & "<br/>")
for each v in c
response.write( v & " = " & c.Item(v) & "<br/>")
next
set c = request.Form
response.write("Form.Count = " & c.Count & "<br/>")
for each v in c
response.write( v & " = " & c.Item(v) & "<br/>")
next
set c = request.ServerVariables
response.write("ServerVariables.Count = " & c.Count & "<br/>")
for each v in c
response.write( v & " = " & c(v) & "<br/>")
next
set c = request.Cookies
response.write("Cookies.Count = " & c.Count & "<br/>")
for each v in c
response.write( v & " = " & c(v) & "<br/>")
next
set c = request.ClientCertificate
response.write("ClientCertificate.Count = " & c.Count & "<br/>")
for each v in c
response.write( v & " = " & c(v) & "<br/>")
next
response.write("</body></html>")
</script>
Tests on the request object:
QueryString.Count = 2
Name = Bill Smith
Country = Canada
ServerVariables.Count = 49
...
QUERY_STRING = Name=Bill+Smith&Country=Canada
What happens here is:
When you request a Web page with a URL contains a "?", everything after "?"
in the URL will be received by the server as the query string.
The query string
will be store in the server variable called "QUERY_STRING". It will also be split
into pairs of names and values and stored in "QueryString" collection.
"&" is used in the query string as delimiters.
Special characters in the query string need to be encoded. For example, " "
is encoded as "+". I believe ASP offers both URL encoding and decoding methods.