[英]How to use one value per request from the Multiple Values extracted using JSON Extractor
Using JSON Extractor, extracted multiple values from response body. 使用JSON Extractor从响应主体中提取多个值。 Debug Sampler -> For eg shows these 3 values
ID_1=212
ID_2=211
ID_3=225
调试采样器->例如,显示这三个值
ID_1=212
ID_2=211
ID_3=225
How to use each of these in the next HTTP Post Request? 如何在下一个HTTP Post Request中使用它们? Like how to use one value for each run?
喜欢如何为每次运行使用一个值?
POST request body {"id"={$ID}} -> doesn't work.
POST请求正文
{"id"={$ID}} -> doesn't work.
However, {"id"={$ID_1}}, {"id"={$ID_2}}, {"id"={$ID_3}}
individually works.I want to avoid manually changing the POST body request everytime. 但是,
{"id"={$ID_1}}, {"id"={$ID_2}}, {"id"={$ID_3}}
单独使用。我想避免每次手动更改POST正文请求。
Add a BeanShell PostProcessor right after you JSON Extractor (in the same level, as a child of the first request) with the below code in code area 在JSON提取器之后(与第一个请求的子项处于同一级别),在代码区域中立即添加一个BeanShell PostProcessor ,并在代码区域中添加以下代码
int matchNr = Integer.parseInt(vars.get("ID_matchNr"));// ID is the reference name of your JSON Extractor
String ID = "";
for(int i = 1; i <= matchNr; i++){
if(i == 1){
ID = "{\"id\"=" + vars.get("ID_" + i) + "}, ";
}
else if(i == matchNr){
ID = ID + "{\"id\"=" + vars.get("ID_" + i) + "}";
}
else{
ID = ID + "{\"id\"=" + vars.get("ID_" + i) + "}, ";
}
vars.put("IDs", ID);
}
Now use the variable ${IDs}
in your POST request body, the value will be something like this {"id"=1}, {"id"=2}, {"id"=3}, {"id"=4}
现在,在您的POST请求正文中使用变量
${IDs}
,该值将如下所示: {"id"=1}, {"id"=2}, {"id"=3}, {"id"=4}
You can use for each loop for your requirement. 您可以根据需要为每个循环使用。 Check jmeter ForEach Controller .
检查jmeter的每个控制器 。 The first example jmx of ForEach can met your requirement.
ForEach的第一个示例jmx可以满足您的要求。 Below reqEx to fetch all.
在reqEx下面提取所有内容。 Then forEach for all regEx as input in "inputVar" and fetch it using returnVar.
然后forEach将所有regEx输入为“ inputVar”中的输入,并使用returnVar获取它。 Pass returnVar to your next request that is HTTP 2.
将returnVar传递给您的下一个HTTP 2请求。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.