[英]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.