向http采样器添加动态数量的参数



我正在寻找一种将动态参数[名称:值]添加到http采样器的方法。

我找到了它的标题,但没有参数。

我有json文件,其中包含方法、参数、头、主体、根据我需要构建和发送http请求的值进行授权。

我成功地设置了HOST、PORT、PATH、HEADERS。。

我想在发送http请求之前设置它的主体、授权和参数。

下面是groovy代码,我在其中从json解析器将json内容解析为jsonparser,我正在设置上面的http。

 String fileContents = new File('../../src/resources/testInput.txt').text
def slurper = new JsonSlurper()
def inputjson = slurper.parseText fileContents
    String httpmethod = inputjson.Method
    sampler.setMethod(httpmethod);
 inputjson.Headers.each{log.info it.each{
key,value -> log.info key 
log.info value
 sampler.getHeaderManager().add(new Header(key,value ));
}
}
是的,我已经找到了查询参数的部分答案。
 inputjson.QueryParams.each{ it.each{
    key,value -> 
     sampler.addArgument(key,value);
    }

最新更新