简体   繁体   English

如何将Bean shell处理器变量传递给jmeter中的HTTP Request body数据

[英]How to pass Bean shell processor variable in to HTTP Request body data in jmeter

I need to pass the Date format variable data from Bean shell processor to http request body 我需要将Date格式的变量数据从Bean shell处理器传递给http请求体

Below is my code and json where I passed variable data but it is not working 下面是我的代码和json,我传递了可变数据,但它不起作用

import java.text.SimpleDateFormat;
import java.util.Date;

Date enrolmentDate = new Date();
enrolmentDate.setDate(enrolmentDate.getDate());//+ ${__Random(1,50,)});
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm");
String formattedDate = df.format(enrolmentDate);
vars.put("StartDate",formattedDate);
log.info("########################"+formattedDate);

Below is the Http Request Body data 下面是Http Request Body数据

{
"articleId":""${ArticleId}",
"startDate":"${formattedDate}",
"endDate":"${Carttodates}"
}

When i run it Start date and end date is shown as ${formattedDate}, what will be the solution? 当我运行它时,开始日期和结束日期显示为$ {formattedDate},解决方案是什么?

and in my JSON body data i want to send Start and End Date like "27/05/2019 14:34 " 在我的JSON正文数据中,我想发送开始和结束日期,如“27/05/2019 14:34”

Below is the Request I got 以下是我收到的请求

PUT data:
{
"articleId":"7694b207-936b-40b9-9c80-4b8097e67da1",
"startDate":"${formattedDate}",
"endDate":"${Carttodates}"
}

您还需要将formattedDate作为变量名称:

vars.put("formattedDate", formattedDate);

Change your request body to 将您的请求正文更改为

{
"articleId":""${ArticleId}",
"startDate":"${StartDate}",
"endDate":"${Carttodates}"
}

The reason why this is required is because you are storing the date in "StartDate" variable in beanshell. 之所以需要这样做是因为您将日期存储在beanshell中的“StartDate”变量中。 Hence, you should use "StartDate" to access the value later in HTTP. 因此,您应该使用“StartDate”稍后在HTTP中访问该值。 The other option is to store the value in "formattedDate" variable in beanshell and then you do not need to change it in HTTP request body. 另一个选项是将值存储在beanshell中的“formattedDate”变量中,然后您不需要在HTTP请求体中更改它。

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

相关问题 JMETER -- 想要调用响应(响应数据 -- 正文)到其他 HTTP 请求的正文数据) - JMETER -- want to call response (response data -- body) to body data of other HTTP request) Jmeter - 如何将多个令牌从 http 登录请求传递到另一个 http 请求 - Jmeter - How to pass multiple tokens from http login request to another http request JMeter - 如何将多行响应数据传递给 ForEach Controller 请求 - JMeter - How to pass Multiline response data to the ForEach Controller request 如何在Jmeter中更改HTTP请求名称 - How to change http request name in Jmeter 将jmeter Http请求的响应数据保存在字符串Java代码中 - Save jmeter Http request's response data in string java code 如何读取Excel文件并将其用作jmeter中不同主体的变量 - How to read excel file and use it as a variable for different body in jmeter Jmeter - 在 Jmeter 中构造一个 URL 和 Z293C9EA246FF9985DC6F62A6 请求 - Jmeter - Constructing a URL in Jmeter with HTTP request Jmeter http 请求完成通知 - Jmeter http request completion notification RandomUtils.nextLong(10L,1000L) 在 JMeter HTTP 请求正文中失败并显示“意外令牌:10L” - RandomUtils.nextLong(10L,1000L) fails with "unexpected token: 10L" in JMeter HTTP Request body 在 Jmeter 的另一个变量中传递变量 - Pass Variable inside the another variable in Jmeter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM