繁体   English   中英

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

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

我需要将Date格式的变量数据从Bean shell处理器传递给http请求体

下面是我的代码和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);

下面是Http Request Body数据

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

当我运行它时,开始日期和结束日期显示为$ {formattedDate},解决方案是什么?

在我的JSON正文数据中,我想发送开始和结束日期,如“27/05/2019 14:34”

以下是我收到的请求

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

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

vars.put("formattedDate", formattedDate);

将您的请求正文更改为

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

之所以需要这样做是因为您将日期存储在beanshell中的“StartDate”变量中。 因此,您应该使用“StartDate”稍后在HTTP中访问该值。 另一个选项是将值存储在beanshell中的“formattedDate”变量中,然后您不需要在HTTP请求体中更改它。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM