简体   繁体   English

如何使用JSON Extractor提取的多个值中的每个请求使用一个值

[英]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.

相关问题 Jmeter json路径提取器 - 如何从提取的值中删除[] - Jmeter json path extractor - How to Remove [ ] from extracted value 试图将值(从 json 路径提取器中提取)传递给下一个 http 请求 - trying to pass the value (which is extracted from json path extractor) to the next http request 我如何基于从json路径提取器提取的值传递n个请求 - How can i pass 'n' number of requests based on value extracted from json path extractor 如何将在JSON路径提取器中提取的变量用于场景的进一步步骤? - How to use variable extracted in JSON path extractor for further steps of scenario? 使用Beanshell后处理器修改从JSON提取器提取的数据 - Using Beanshell Postprocessor to modify the data extracted from JSON extractor 使用RegEx Extractor从JSON响应中提取多个值 - Pulling multiple values from JSON response using RegEx Extractor 如何在jmeter中使用正则表达式提取器从多个数组响应数据中检索JSON值? - How to retrieve the JSON value from multiple array response data using regular expression extractor in jmeter? 使用JSON提取器从响应中提取值 - Using JSON extractor to extract values from the response 使用 Json Extractor 从 Jmeter 中 POST 请求的 Json 响应中提取值 - Extracting value from Json response of POST request in Jmeter using Json Extractor 我想在 Jmeter 中使用其他 controller 中使用 JSON 提取器提取的几个变量 - I want to use few variables that are extracted using JSON extractor in other controller in Jmeter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM