如何使用jmeter发送多个json主体? [英] How to send multiple json body using jmeter?
问题描述
我已经编写了REST API,现在我的要求是使用JMeter的POST方法将多个JSON正文发送到API.我有一个带有四个值(1,2,3,4)的csv文件.在这四个文件中的每个文件中,我都有JSON正文.我用过:
I have written a REST API and now my requirement is to send the multiple JSON body to the API using POST method from JMeter. I have a csv file with four values(1,2,3,4). And in each of the four files I have the JSON body. I used :
步骤1)将csv文件添加到jmeter并创建引用并将其命名为JSON_FILE
步骤2)${__FileToString(C:Path_to_csv_file/${__eval(${JSON_FILE})}.txt,,)}
但是从这里我只能访问第一个文件,即以一个命名的文件.如何将所有文件的正文发送到API? 非常感谢您的帮助.
But from this I am able to access only first file i.e which is named with one. How do I send the body of all file to the API? Help is highly appreciated.
推荐答案
在HTTP Sampler中使用主体数据,如下所示:
Use Body data as follows in HTTP Sampler:
{__FileToString(${JSON_FILE},,)}
您必须将所有文件路径放入plan.csv
文件中.每行应该有一个文件路径.
You have to put all the file path in your plan.csv
file. At each line, there should be a file path.
示例:
假设您要在HTTP采样器中使用4个带有JSON正文的文件.
Suppose, you have 4 files with JSON body which you want to use in your HTTP sampler.
在您的CSV文件中将这4个文件的文件路径指定为plan.csv
.每行包含一个这样的文件路径:
Give the file path of these 4 files in your CSV file which is plan.csv
. Each line contains a file path like this:
/User/file/file1.json
/User/file/file2.json
/User/file/file3.json
/User/file/file4.json
现在,在您的CSV数据集配置中,使用包含所有文件路径的CSV文件的正确文件名,并为其指定一个变量名,例如JSON_FILE
.
Now, in your CSV data set config, Use the proper file name of CSV file which contains all the file path and give it a variable name like JSON_FILE
.
现在,在您的身体数据中使用{__FileToString(${JSON_FILE},,)}
此行.还要相应地使用循环计数值.
Now, Use {__FileToString(${JSON_FILE},,)}
this line in your Body data. Also use the loop count value accordingly.
这篇关于如何使用jmeter发送多个json主体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!