【问题标题】:Reading a Request Parameter as a List in Groovy and SoapUI在 Groovy 和 SoapUI 中将请求参数读取为列表
【发布时间】:2014-03-05 21:34:36
【问题描述】:

我正在使用带有 MockService“功能”的 SoapUI 4.6.4。

此服务将收到如下请求:

code=abcdef&code=123456&code=78910

在 SoapUI(接受 Groovy 代码)的“OnRequest Script”选项卡中,我想从查询字符串参数中检索所有“代码”并循环遍历列表(对每个代码执行一些操作并更改写下回复)

到目前为止,这是我的代码:

def httpResponse = mockRequest.httpResponse

httpResponse.setContentType("application/json;charset=utf-8")
// Get all "codes" from request as a list
// loop trought list of codes one by one

def generatedResponse = "";
httpResponse.writer << "{\"codes\": [" + generatedResponse + "]}"

httpResponse.status = 200

【问题讨论】:

    标签: rest groovy get soapui


    【解决方案1】:

    我认为最简单的:

    def arrayOfCodes = "code=abcdef&code=123456&code=78910".replace("code=", "").split("&")
    

    【讨论】:

    • 谢谢。如何从请求中获取查询字符串 code=abcdef&code=123456&code=78910?
    猜你喜欢
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-09
    • 1970-01-01
    相关资源
    最近更新 更多