如何在 JMeter HTTP 请求中更改 Post Body 的内容 [英] How to change content of Post Body in JMeter HTTP Request

查看:42
本文介绍了如何在 JMeter HTTP 请求中更改 Post Body 的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请原谅我的无知,因为我是一个 jmeter 菜鸟.我的网络服务接受 JSON 对象,因此我能够编写一个基本测试,在该测试中,我在 http 请求的Post Body"部分创建了一个带有 JSON 对象的 HTTP 请求.

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.

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

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 请求默认对象,其中包含一堆 HTTP 请求,其中包含不同的 JSON 对象,然后使用一个随机控制器,用于在每次传递时随机通过我的多个 HTTP 请求.

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.

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

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.


更新:所以我尝试了第二种方法,它似乎有效.我有 3 个不同的 HTTP 请求,每个请求被命中的次数因运行而异.我仍然邀请社区提供答案,因为我想看看专业人士如何解决与我类似的问题.


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.

推荐答案

通过说csv 文件或",您自己已经部分回答了您的问题.以下是具体内容.

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

您必须在测试计划中使用 CSV 数据集配置 从 CSV 读取数据.在您的帖子正文中,使用从 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 数据集配置的截屏.

这篇关于如何在 JMeter HTTP 请求中更改 Post Body 的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆