lotus agent request_content如何分隔字段

时间:2015-11-11 10:29:03

标签: html lotus-notes lotus-domino lotusscript

我有一个用lotusscript运行的莲花代理。构建浏览器我将表单数据发布到网络服务器,我使用以下lotusscript接收这些数据:request_method = doc.GetItemValue( "request_content" )(0)

但是,如果我有一个名称和phonenumber的表格。然后我的代理人会收到name=bla&phonenumber=243525

如何实际分隔这些字段,其次如何在此代理上接收XML,以便我可以提取并放入文档。我google了很多但仍然没有解决方案。

3 个答案:

答案 0 :(得分:2)

如果客户端进行GET或POST,则获取数据的方式会有所不同。 如果这是一个get,则所有参数都以url格式在url中。

网上很多很多资源都会给你一些代码来解析这个网址,并获得名称和价值,在goolge中进行简单搜索会带来:http://searchdomino.techtarget.com/tip/Parsing-URL-Parameters-with-Ease

我通常使用以下代码,它在文档上下文中添加在url或post上收到的字段。

    Dim s As NotesSession
Set s = New notessession
Set doc = s.documentcontext
Dim myQuerystring As String

If doc Is Nothing Then
    logErrorEX "getting a call without document context ?!?","", doc,""
    GoTo returnErr
End If
If doc.QUERY_STRING_DECODED(0)<>"" Then'it's a GET
    myQuerystring = doc.QUERY_STRING_DECODED(0)
ElseIf doc.QUERY_STRING(0)<>"" Then
    myQuerystring = doc.QUERY_STRING(0)
    'decode it !
ElseIf doc.REQUEST_CONTENT(0)<>"" Then'it's a POST
    myQuerystring = doc.REQUEST_CONTENT(0) ' WARNING this is for POST but you will have to decode !!!
    'decode it !
Else
    logErrorEX "getting a call with document context but without query_string?!?","", doc,""
    GoTo returnErr
End if
Call ExplodeQueryString(myQuerystring, doc)

Private Sub  ExplodeQueryString (QueryString As String,doc As NotesDocument )

Dim ArgsList As Variant 

ArgsList = Split (QueryString,  "&")
If IsArray(ArgsList) Then 
    debugString = debugString+"ArgsList is an array of " & UBound(ArgsList) 
Else
    debugString = debugString+"ArgsList is NOT an array ??? " & ArgsList
End if
Dim ArgKey As String
Dim ArgValue As String
ForAll Arg In ArgsList
    If left$(Arg, 1)= "_" Or Left$(Arg, 1)= "%" Then
        'ignore it      
    else 
        ArgKey = strleft(Arg, "=")
        If ArgKey = "" Then
            'ignore it?
        else
            ArgValue = strright$(Arg, "=")
            '               AgentArgs(ArgKey) = ArgValue
            doc.Replaceitemvalue ArgKey, ArgValue
        End If
    End if
End ForAll
End Sub

我没有声明像debugString这样的全局变量来缩短。

答案 1 :(得分:0)

您看到的格式是所有网络浏览器软件用来对表单中的字段数据进行编码的惯例。您可以在Emmanual发布的代码中使用类似于ExplodeQueryString函数的函数来解析它。在我看来,他正在接受每个&#34;&amp; name&#34; part并创建一个具有该名称的NotesItem,并使用它来存储&#34; = value&#34;一部分。您可以这样做,或者您可以使用列表,或任何最符合您要求的列表。

如果不使用&amp; name = value约定,则不存在禁止以其他格式发送POST数据的规则。它只需要在发送软件和接收方软件之间达成协议。如果他们想在POST数据中发送XML,那很好。您可以使用标准的XML解析函数来处理它。 Notes附带了一个NotesDOMParsesr类,您可以根据需要使用它。如果您在Windows上运行,则可以使用Microsoft.XMLDOM。

答案 2 :(得分:0)

我前一段时间写了一篇课程,完全符合你的要求。它将查询字符串(或请求内容)拆分为值列表,名称为列表标记。

http://blog.texasswede.com/free-code-class-to-read-url-name-value-pairs/

这是代码(我通常把它放在一个名为Class.URL的脚本库中):

%REM
    Library Class.URL
    Created Oct 9, 2014 by Karl-Henry Martinsson
    Description: Lotusscript class to handle incoming URL (GET/POST).
%END REM
Option Public
Option Declare

%REM
    Class URLData
    Description: Class to handle URL data passed to web agent
%END REM
Class URLData
    p_urldata List As String

    %REM
        Sub New()
        Description: Create new instance of URL object from NotesDocument 
    %END REM
    Public Sub New()
        Dim session As New NotesSession
        Dim webform As NotesDocument
        Dim tmp As String
        Dim tmparr As Variant  
        Dim tmparg As Variant
        Dim i As Integer

        '*** Get document context (in-memory NotesDocument)
        Set webform = session.DocumentContext
        '*** Get HTTP GET argument(s) after ?OpenAgent
        tmp = FullTrim(StrRight(webform.GetItemValue("Query_String")(0),"&"))
        If tmp = "" Then
            '*** Get HTTP POST argument(s) after ?OpenAgent
            tmp = FullTrim(StrRight(webform.GetItemValue("Request_Content")(0),"&"))    
        End If
        '*** Separate name-value pairs from each other into array
        tmparr = Split(tmp,"&")      
        '*** Loop through array, split each name-value/argument 
        For i = LBound(tmparr) To UBound(tmparr)
            tmparg = Split(tmparr(i),"=")
            p_urldata(LCase(tmparg(0))) = Decode(tmparg(1))
        Next
    End Sub

    %REM
        Function GetValue
        Description: Get value for specified argument.
        Returns a string containing the value.
    %END REM
    Public Function GetValue(argname As String) As String
        If IsElement(p_urldata(LCase(argname))) Then
            GetValue = p_urldata(LCase(argname))
        Else        
            GetValue = ""   
        End If
    End Function

    %REM
        Function IsValue
        Description: Check if specified argument was passed in URL or not.
        Returns boolean value (True or False).
    %END REM
    Public Function IsValue(argname As String) As Boolean
        If IsElement(p_urldata(LCase(argname))) Then
            IsValue = True
        Else        
            IsValue = False 
        End If
    End Function


    '*** Private function for this class
    '*** There is no good/complete URL decode function in Lotusscript
    Private Function Decode(txt As String) As String
        Dim tmp As Variant 
        Dim tmptxt As String
        tmptxt = Replace(txt,"+"," ")
        tmp = Evaluate(|@URLDecode("Domino";"| & tmptxt & |")|)
        Decode = tmp(0)
    End Function

End Class

这就是你如何使用它:

Option Public
Option Declare
Use "Class.URL"

Sub Initialize
    Dim url As URLData

    '*** Create new URLData object
    Set url = New URLData()

    '*** MIME Header to tell browser what kind of data we will return
    Print "content-type: text/html"

    '*** Check reqired values for this agent
    If url.IsValue("name")=False Then
        Print "Missing argument 'name'."
        Exit Sub
    End If

    '*** Process name argument
    If url.GetValue("name")="" Then
        Print "'Name' is empty."
    Else
        Print "Hello, " + url.GetValue("name") + "!"
    End If

End Sub