我正在使用SoapUI 4.6.4和MockService“功能”。
此服务将收到如下请求:
code=abcdef&code=123456&code=78910
在SoapUI的“OnRequest Script”选项卡中(它接受Groovy代码),我想从查询字符串参数中检索所有“代码”并循环遍历列表(对每个代码执行一些操作并更改写下回复)
到目前为止,这是我的代码:
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
答案 0 :(得分:0)
我认为最简单:
def arrayOfCodes = "code=abcdef&code=123456&code=78910".replace("code=", "").split("&")