Figures
Figure 1 ExtractHTTPGetParams
' ==============================================
'   Fills the QueryString collection
' ==============================================
Public Sub ExtractHttpGetParams(ByVal strParams As String)
    Dim a() As String
    Dim e As Variant
    
    ' QueryString is an instance of Scripting.Dictionary
    ' Such an object supports a RemoveAll method
    m_objRequest.QueryString.RemoveAll
    
    a = Split(strParams, "&")
    For Each e In a
            Dim v() As String
            v = Split(e, "=")
            m_objRequest.AddToQueryString v(0), v(1)
    Next
End Sub

' ==============================================
'   Fills the Form collection
' ==============================================
Public Sub ExtractHttpPostParams(ByVal strParams As String)
    Dim a() As String
    Dim e As Variant
    
    ' Form is an instance of Scripting.Dictionary
    ' Such an object supports a RemoveAll method
    m_objRequest.Form.RemoveAll
    
    a = Split(strParams, "&")
    For Each e In a
            Dim v() As String
            v = Split(e, "=")
            m_objRequest.AddToForm v(0), v(1)
    Next
End Sub
Figure 2 Implementing Request
Option Explicit
 
Private m_collForm As Object
Private m_collServerVariables As Object
Private m_collQueryString As Object

' ===========================================
'   The Form property
' ===========================================
Public Property Get Form() As Object
    Set Form = m_collForm
End Property

' ===========================================
'   The QueryString property
' ===========================================
Public Property Get QueryString() As Object
    Set QueryString = m_collQueryString
End Property

' ===========================================
'   The ServerVariables property
' ===========================================
Public Property Get ServerVariables() As Object
    Set ServerVariables = m_collServerVariables
End Property


' ===========================================
'   Helper Methods
' ===========================================
Public Sub AddToQueryString(ByVal strKey As String, ByVal strValue As String)
    m_collQueryString.Add strKey, strValue
End Sub

Public Sub AddToForm(ByVal strKey As String, ByVal strValue As String)
    m_collForm.Add strKey, strValue
End Sub

Public Sub AddToServerVariables(ByVal strKey As String, ByVal strValue As String)
    m_collServerVariables.Add strKey, strValue
End Sub

Private Sub Class_Initialize()
    Set m_collQueryString = CreateObject("Scripting.Dictionary")
    Set m_collForm = CreateObject("Scripting.Dictionary")
    Set m_collServerVariables = CreateObject("Scripting.Dictionary") 
End Sub

Private Sub Class_Terminate()
    Set m_collQueryString = Nothing
    Set m_collForm = Nothing
    Set m_collServerVariables = Nothing
End Sub
Figure 5 The Dictionary Object
Properties
Description
CompareMode
Sets and returns the comparison mode for string keys
Count
Read-only property which returns the number of items in the dictionary
Item
Sets or returns an item for the specified key
Key
Allows you to change the key of an item
Methods
Description
Add
Adds a new item to the dictionary
Exists
Verifies whether a given key exists in the dictionary
Items
Returns an array with all the items
Keys
Returns an array with all the keys
Remove
Removes the item identified by the specified key
RemoveAll
Removes all the items in the dictionary
Figure 6 Preparing the QueryString
' =========================================================
'    Detects the click on a Submit button
' =========================================================
Private Function m_htmlDoc_onclick() As Boolean
    Dim strTag As String, strType As String
    Dim objSrc As HTMLInputButtonElement
    Set objSrc = m_htmlWindow.event.srcElement
    strTag = objSrc.tagName
    
    If (strTag = "INPUT") Then
        If objSrc.Type = "submit" Then
            ' Build the Form/QueryString collections
            Set m_htmlForm = objSrc.Form
            BuildRequestCollections m_htmlForm.method
            
            ' redirect the action
            LocalNavigate objSrc.Form.Action
        End If
    End If
    
    ' Returns False, which means cancelling the default action
End Function


' =========================================================
'    Prepares the QueryString and Form collections
' =========================================================
Private Sub BuildRequestCollections(ByVal how As String)
    Dim e As HTMLInputElement
    Dim buf As String
    
    ' Visit the form's content
    For Each e In m_htmlForm.children
        Dim strVal As String, strName As String
            
        strVal = "": strName = ""
        If Not IsNull(e.getAttribute("Name")) Then
            If e.getAttribute("Name") >< "" Then
                strName = e.getAttribute("Name")
            End If
        End If
        If Not IsNull(e.getAttribute("value")) Then
            If e.getAttribute("value") >< "" Then
                strVal = e.getAttribute("value")
            End If
        End If
                
        If strName >< "" And strVal >< "" Then
            If buf >< "" Then buf = buf & "&"
            buf = buf & strName & "=" & strVal
        End If
    Next
        
    ' Populates the proper dictionary
    If LCase(how) = "post" Then
        m_asp.ExtractHttpPostParams buf
    Else
        m_asp.ExtractHttpGetParams buf
    End If
End Sub


' =========================================================
'    Initializes the HTML objects 
' =========================================================
Private Sub WB_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    Set m_htmlDoc = WB.Document
    Set m_htmlWindow = m_htmlDoc.parentWindow
End Sub
Figure 9 Online Querying

Figure 9 Online Querying
Figure 10 Offline Querying

Figure 10 Offline Querying
Figure 11 Custom Variables
' ====================================================================
'     Excerpt from the LocalNavigate method
' ====================================================================

    ' Populate the ServerVariables collection
    Dim temp As String * 40
    Dim nLen As Long
    buf = "": nLen = 40
    
    buf = buf & "HTTP_USER_AGENT" & "=" & "ASP-Offline-Browser" & "&"
    buf = buf & "PATH_TRANSLATED" & "=" & strAspFile & "&"
    
    ' -1 because GetUserName returns the length + NULL
    GetUserName temp, nLen
    buf = buf & "LOGON_USER" & "=" & Left(temp, nLen - 1) & "&"
    
    
    ' GetComputerName returns the length without final NULL
    nLen = 40
    GetComputerName temp, nLen
    buf = buf & "SERVER_NAME" & "=" & Left(temp, nLen) & "&"
    
    buf = buf & "OFFLINE" & "=" & "yes"
    m_asp.FillServerVariables buf' ====================================================================
'     The FillServerVariables method of the CAspParser class
' ====================================================================

'   Fills the ServerVariables collection

Public Sub FillServerVariables(ByVal strParams As String)
    Dim a() As String
    Dim e As Variant
    
    ' Form is an instance of Scripting.Dictionary
    ' Such an object supports a RemoveAll method
    m_objRequest.ServerVariables.RemoveAll
    
    a = Split(strParams, "&")
    For Each e In a
            Dim v() As String
            v = Split(e, "=")
            m_objRequest.AddToServerVariables v(0), v(1)
    Next
End Sub
Figure 12 ServerVariables

Figure 12 ServerVariables
Figure 13 FileSystem
<%
function EnumFiles
    for each d in FileSystem.Drives
        Response.Write d.VolumeName & "<br>"
    next
end function

function EnumVariables
    for each c in Request.ServerVariables
        Response.Write c & "<br>"
    next
end function
%>

<html>
<body>
<%
    if X_OFFLINE then 
        Response.Write "Working offline"
        Response.Write "<hr>"
        EnumFiles
    else
        Response.Write "Working online"
        Response.Write "<hr>"
        EnumVariables
    end if
%>


</body>
</html>
Page view tracker