简体   繁体   English

JMeter:如何为每个线程数发送具有不同请求正文的 HTTP 请求?

[英]JMeter: How to send HTTP requests with different request body for each thread count?

I am testing a REST API that creates a user.我正在测试创建用户的 REST API。 This API uses POST method and requires a json payload.此 API 使用 POST 方法并需要 json 有效负载。 I am using the HTTP Request Sampler for my requests which accepts a file for the request payload.我正在为我的请求使用 HTTP 请求采样器,它接受请求负载的文件。 The issue I'm having is that the request returns a 409 Conflict for all the hits except for the first thread because after the first thread is executed, the user already exists.我遇到的问题是,除了第一个线程之外,请求为所有命中返回 409 Conflict,因为在执行第一个线程后,用户已经存在。 Is there a way I can tell JMeter to pick a different payload before each request?有没有办法告诉 JMeter 在每个请求之前选择不同的有效负载? How can I organize my request payload for this purpose?我如何为此目的组织我的请求有效负载?

In your payload file you can concatenate your username with jMeter function that makes it unique:在您的负载文件中,您可以将您的用户名与 jMeter 函数连接起来,使其独一无二:

"username": "user ${__time()}"

instead of time function you can either use __UUID or even a __counter function.您可以使用 __UUID 甚至 __counter 函数来代替时间函数。 You can also combine the functions together.您也可以将这些功能组合在一起。 Have a look here:看看这里:

https://www.blazemeter.com/blog/apache-jmeter-functions-introduction https://www.blazemeter.com/blog/apache-jmeter-functions-introduction

You will have to parametrized your test plan and use CSV data set config to use the data from csv file.您必须参数化您的测试计划并使用 CSV 数据集配置来使用来自 csv 文件的数据。 I have created a beginners screen cast to explain how to use csv data set config .我创建了一个初学者截屏来解释如何使用 csv 数据集配置

As you mentioned you cannot reuse the same data, you will have to either create a big enough csv to match or your concurrent user needs, or use once only controller to not replay those request again, which will create duplicate users.正如您提到的,您不能重用相同的数据,您必须创建一个足够大的 csv 来匹配或您的并发用户需求,或者仅使用一次控制器来不再重播这些请求,这将创建重复的用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM