JMeter,后处理样本
JMeter, postprocessing a sample
在我的项目中,我想为 JMeter 实现一个插件。
所以目前我停留在采样器 - post处理步骤。
@Override
public void postProcessSampler(HTTPSamplerBase sampler, SampleResult result)
{
super.postProcessSampler(sampler, result);
String postData = sampler.getPropertyAsString(HTTPSamplerBase.ARGUMENTS);
// ...
// apply some operations to postData
// ...
//
// try to write it back to sampler : approach1
// sampler.removeProperty(HTTPSamplerBase.ARGUMENTS);
// sampler.addNonEncodedArgument(HTTPSamplerBase.ARGUMENTS, postData, "");
// Fails
}
所以在 post 处理步骤我想更改请求主体,whcih 通常存储在 HTTPSamplerBase.ARGUMENTS
属性 中。但是,不知何故我无法为此字段设置任何内容。用另一个字符串重新定义它会给我一个 class 转换错误。如果我尝试使用字符串进行操作,则会出现调用异常...
所以我的问题是,更改采样器 post 主体的正确方法是什么?
问候并感谢您
试试 HTTPSamplerBase.getArguments() function,示例代码:
sampler.getArguments().removeAllArguments();
sampler.addNonEncodedArgument("foo","bar","");
sampler.setPostBodyRaw(true);
另请注意,对于这种形式的 post 处理,您甚至不需要想出一个插件,所有这些都可以通过 JSR223 PostProcessor and Groovy 语言完成。上面的代码应该可以正常工作
在我的项目中,我想为 JMeter 实现一个插件。
所以目前我停留在采样器 - post处理步骤。
@Override
public void postProcessSampler(HTTPSamplerBase sampler, SampleResult result)
{
super.postProcessSampler(sampler, result);
String postData = sampler.getPropertyAsString(HTTPSamplerBase.ARGUMENTS);
// ...
// apply some operations to postData
// ...
//
// try to write it back to sampler : approach1
// sampler.removeProperty(HTTPSamplerBase.ARGUMENTS);
// sampler.addNonEncodedArgument(HTTPSamplerBase.ARGUMENTS, postData, "");
// Fails
}
所以在 post 处理步骤我想更改请求主体,whcih 通常存储在 HTTPSamplerBase.ARGUMENTS
属性 中。但是,不知何故我无法为此字段设置任何内容。用另一个字符串重新定义它会给我一个 class 转换错误。如果我尝试使用字符串进行操作,则会出现调用异常...
所以我的问题是,更改采样器 post 主体的正确方法是什么?
问候并感谢您
试试 HTTPSamplerBase.getArguments() function,示例代码:
sampler.getArguments().removeAllArguments();
sampler.addNonEncodedArgument("foo","bar","");
sampler.setPostBodyRaw(true);
另请注意,对于这种形式的 post 处理,您甚至不需要想出一个插件,所有这些都可以通过 JSR223 PostProcessor and Groovy 语言完成。上面的代码应该可以正常工作