如果 jmeter 中的 HTTP 请求,则在请求 URL 和 body 中传递自动增量变量

Pass auto increment variable in request URL and body if HTTP request in jmeter

我有一个端点接受 auto-increment 整数 id 作为路径参数的一部分,并且在请求中 body 也有一些键也接受它。

例如端点是http://foo.bar/{id}

而body是

{
 "someid" : someno+{id passed in url},
 "some world :"fixed string" + "id passed in url"
}

我尝试直接使用 __counter() 代替我的 {id},但它不起作用,在调试时发现它没有替换值并且它仅作为文字出现。

添加 Counter 并在任意位置调用您定义的参考名称。

Allows the user to create a counter that can be referenced anywhere in the Thread Group

有一个 __counter() function 每次被调用时都会生成一个递增的数字,您可以将其声明放入 URL 中,例如:

${__counter(FALSE,counter)}

和请求正文中的 JMeter Variable 引用:

{
 "someid" : someno+${counter},
 "some world :"fixed string" + "id passed in url"
}

这样您每次通话都会得到一个唯一的递增号码

更多信息:How to Use a Counter in a JMeter Test