There are 2 requests.
In the first request through the Regular Expression Extractor I get data that looks like
VAR_1=foo
VAR_2=bar
VAR_3=base
VAR_N=NNN
VAR_matchNr=N
The data is stored in the variable VAR.
In the second request I added the JSR223 preprocessor. I added the following code to it:
def array = []
1.upto(vars.get('VAR_matchNr') as int, { index ->
array.add(vars.get('VAR_' + index))
})
vars.put('array', new groovy.json.JsonBuilder(array).toPrettyString());
When the script runs, everything is processed correctly, the data from the VAR variable is converted into an array.
I have the following question:
I need to pass the received data in the parameters of a POST request. Right now I'm passing through the ${array} variable. But the entire array is transferred at once and the request is executed incorrectly. enter image description here
How can I make sure that each array value in the query parameters is written as a separate parameter? At the same time, I don’t know for sure how many parameters there will be, there can be from 0 to 20 enter image description here