Here's my version of the code for parsing the Request_Content field
[<br clear="all" /><code>]
Public Class RequestContentParser
Private psRC As String
Private piAmpPos As Integer
Sub new(Byval sRequest_Content As String)
psRC = sRequest_Content
piAmpPos = 0
End Sub
Public Function Unescape(Byval s As String) As String
Dim iP As Integer
Dim sL As String
Dim sM As String
Dim sR As String
iP = Instr(s,"%")
If iP <> 0 Then
sL = Left$(s,iP-1)
sM = Mid$(s,iP+1,2)
sR = Mid$(s, iP+3)
Unescape = sL & Chr(Cint("&h" & sM)) & Unescape(sR)
Else
Unescape = s
End If
End Function
Public Function GetNextField(sFieldName As String, sValue As String) As
Variant 'boolean, true if successful, false if no more fields
Dim iEqPos As Integer
Dim iFieldPos As Integer
On Error 1 Goto ErrorSub
If piAmpPos = -1 Then Error 1
iFieldPos = piAmpPos + 1
iEqPos = Instr(iFieldPos, psRC, "=")
If iEqPos = 0 Then Error 1
sFieldName = Mid(psRC, iFieldPos, iEqPos - iFieldPos)
piAmpPos = Instr(iEqPos, psRC, "&")
If piAmpPos <> 0 Then
sValue = Unescape(Mid(psRC, iEqPos + 1, piAmpPos - iEqPos - 1))
Else
sValue = Unescape(Mid(psRC, iEqPos + 1))
piAmpPos = -1 'flag that there are no more fields
End If
GetNextField = True
ExitSub:
Exit Function
ErrorSub:
GetNextField = False
Resume ExitSub
End Function
Public Function GetFieldValue(sFieldName As String) As String
Dim iAmpPos As Integer
Dim iFieldPos As Integer
Dim iValPos As Integer
Dim sValue As String
iFieldPos = Instr("&" + psRC, "&" + sFieldName + "=")
If iFieldPos = 0 Then
GetFieldValue = ""
Else
iValPos = Len(sFieldName) + 2
iAmpPos = Instr(iValPos, psRC, "&")
If iAmpPos = iValPos Then
GetFieldValue = ""
Else
GetFieldValue = Unescape(Mid(psRC, iValPos, iAmpPos - iValPos))
End If
End If
End Function
End Class
[</code>]
You use it by putting this code in your declarations, and having the line
From there, you do something like:
[<code>]
Set Session = New NotesSession
Set RCP = New RequestContentParser(Session.DocumentContext.Request_Content(0))
Do while RCP.GetNextDocument(sFieldName, sValue)
Print sFieldName + { = "} + sValue + {"<br>}
Loop
[</code>]
The GetFirstField method is unnecessary unless you need to start from the
begining a second time.
You can also get a specific field value with GetFieldValue.
This thread helped me out a LOT today.
Here's my version of the code for parsing the Request_Content field
[<br clear="all" /><code>] Public Class RequestContentParser Private psRC As String Private piAmpPos As Integer Sub new(Byval sRequest_Content As String) psRC = sRequest_Content piAmpPos = 0 End Sub Public Function Unescape(Byval s As String) As String Dim iP As Integer Dim sL As String Dim sM As String Dim sR As String iP = Instr(s,"%") If iP <> 0 Then sL = Left$(s,iP-1) sM = Mid$(s,iP+1,2) sR = Mid$(s, iP+3) Unescape = sL & Chr(Cint("&h" & sM)) & Unescape(sR) Else Unescape = s End If End Function Public Function GetNextField(sFieldName As String, sValue As String) As Variant 'boolean, true if successful, false if no more fields Dim iEqPos As Integer Dim iFieldPos As Integer On Error 1 Goto ErrorSub If piAmpPos = -1 Then Error 1 iFieldPos = piAmpPos + 1 iEqPos = Instr(iFieldPos, psRC, "=") If iEqPos = 0 Then Error 1 sFieldName = Mid(psRC, iFieldPos, iEqPos - iFieldPos) piAmpPos = Instr(iEqPos, psRC, "&") If piAmpPos <> 0 Then sValue = Unescape(Mid(psRC, iEqPos + 1, piAmpPos - iEqPos - 1)) Else sValue = Unescape(Mid(psRC, iEqPos + 1)) piAmpPos = -1 'flag that there are no more fields End If GetNextField = True ExitSub: Exit Function ErrorSub: GetNextField = False Resume ExitSub End Function Public Function GetFieldValue(sFieldName As String) As String Dim iAmpPos As Integer Dim iFieldPos As Integer Dim iValPos As Integer Dim sValue As String iFieldPos = Instr("&" + psRC, "&" + sFieldName + "=") If iFieldPos = 0 Then GetFieldValue = "" Else iValPos = Len(sFieldName) + 2 iAmpPos = Instr(iValPos, psRC, "&") If iAmpPos = iValPos Then GetFieldValue = "" Else GetFieldValue = Unescape(Mid(psRC, iValPos, iAmpPos - iValPos)) End If End If End Function End Class [</code>]
You use it by putting this code in your declarations, and having the line
From there, you do something like: [<code>] Set Session = New NotesSession Set RCP = New RequestContentParser(Session.DocumentContext.Request_Content(0)) Do while RCP.GetNextDocument(sFieldName, sValue) Print sFieldName + { = "} + sValue + {"<br>} Loop [</code>]
The GetFirstField method is unnecessary unless you need to start from the begining a second time.
You can also get a specific field value with GetFieldValue.
Enjoy, and Thanks!