如何在JMeter HTTP请求中更改Post Body的内容

时间:2022-06-01 17:01:26

Please forgive my ignorance as I'm a jmeter noob. My webservice accepts JSON objects so I was able to write a rudimentary test where I create an HTTP Request with a JSON object in the "Post Body" portion of the http request.

请原谅我的无知,因为我是一个jmeter noob。我的webservice接受JSON对象,所以我能够编写一个基本的测试,我在http请求的“Post Body”部分创建一个带有JSON对象的HTTP请求。

Anyway, what I want to do is have the HTTP Request choose a different JSON object from a csv file or some other input mechanism so that I can randomize the types of queries that are being run during the load test. Is there a way to do this? The closest is probably using variables (section 4.11 in the user manual) but I have a feeling that's not how variables are used.

无论如何,我想要做的是让HTTP请求从csv文件或其他一些输入机制中选择一个不同的JSON对象,以便我可以随机化在负载测试期间运行的查询类型。有没有办法做到这一点?最接近的可能是使用变量(用户手册中的4.11节),但我感觉不是变量的使用方式。

A second way I've theorized (although I haven't tried yet since I think the method above is easier) is to create a HTTP Request Default obj with a bunch of HTTP Requests with different JSON objects in them and then use a Random Controller to randomly go thru my multiple HTTP Requests on each pass.

我理论化的第二种方式(虽然我还没有尝试,因为我认为上面的方法更容易)是创建一个HTTP请求默认obj,其中包含一堆HTTP请求,其中包含不同的JSON对象,然后使用随机控制器在每次传递中随机地通过我的多个HTTP请求。

If there's a third way, I'm all ears to learn how to use this tool. I'll continue to read and possibly experiment with plan B above. Thanks in advance for any help you can give me.

如果还有第三种方式,我很乐意学习如何使用这个工具。我将继续阅读并可能尝试上面的计划B.在此先感谢您提供的任何帮助。


UPDATE: So I tried the second way and it seems to work. I had 3 different HTTP requests and the number of times each request gets hit varies from run to run. I still invite answers from the community since I'd like to see what the pros do for issues similar to mine.

更新:所以我尝试了第二种方式,它似乎工作。我有3个不同的HTTP请求,每个请求被命中的次数因运行而异。我仍然会邀请社区的答案,因为我想看看专业人士对我的问题做些什么。

1 个解决方案

#1


4  

You have partially answered your question yourself, by saying "csv file or". Here are the specifics.

您已经通过说“csv文件或”来自己部分回答了您的问题。这是具体细节。

You will have to use CSV data set config in your test plan to read data from CSV. In your post body, use the variables read from CSV.

您必须在测试计划中使用CSV数据集配置来从CSV读取数据。在帖子正文中,使用从CSV读取的变量。

Here is a screen cast showing how to use csv data set config.

这是一个显示如何使用csv数据集配置的屏幕演示。

#1


4  

You have partially answered your question yourself, by saying "csv file or". Here are the specifics.

您已经通过说“csv文件或”来自己部分回答了您的问题。这是具体细节。

You will have to use CSV data set config in your test plan to read data from CSV. In your post body, use the variables read from CSV.

您必须在测试计划中使用CSV数据集配置来从CSV读取数据。在帖子正文中,使用从CSV读取的变量。

Here is a screen cast showing how to use csv data set config.

这是一个显示如何使用csv数据集配置的屏幕演示。