
Params | 347
HttpRequest
Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
' Get a String with all the HTTP headers
AllHttp = Request.ServerVariables("ALL_HTTP")
' Use Replace to format the String
AllHttp = Replace(AllHttp, "HTTP", "<br/>HTTP"
Message.Text &= AllHttp & "<br/><br/>"
Dim Counter1, Counter2 As Integer
Dim Keys(), subKeys( ) As String
Dim HeaderColl As NameValueCollection
' Load Headers into NameValueCollection
HeaderColl=Request.Headers
' Get keys into an array
Keys = HeaderColl.AllKeys
For Counter1 = 0 To Keys.GetUpperBound(0)
Message.Text &= "Key: " & Keys(Counter1) & "<br/>"
' Get all values under this key
subKeys = HeaderColl.GetValues(Counter1)
For Counter2 = 0 To subKeys.GetUpperBound(0)
Message.Text &= "Value " & CStr(Counter2) & ": " & _
subKeys(Counter2) & "<br/>"
Next Counter2
Next Counter1
End Sub
Notes
The Headers collection returns only the HTTP headers that were sent as a part of
the current request, as opposed to the ServerVariables collection (described later
in this section), which contains keys for every HTTP header, regardless of whether
a value was passed.
If all you need to do is write the HTTP headers to a file or display them in the
browser, it may be simpler to use the ServerVariables collection. In cases when
you need to access a specific HTTP header by name or loop through the collec- ...