向http sampler添加动态数量的参数

时间:2016-05-17 07:29:50

标签: jmeter

我正在寻找一种方法将动态参数[name:value]添加到http sampler。

我找到了标题而不是参数。

我有json文件,其中包含方法,参数,标题,正文,授权,根据我需要构造和发送http请求的值。

我成功直到设置HOST,PORT,PATH,HEADERS ..

我想在发送http请求之前为body,authorization,parameters设置它。

下面是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 ));
}
}

1 个答案:

答案 0 :(得分:0)

是的,我找到了查询参数的部分答案。

 inputjson.QueryParams.each{ it.each{
    key,value -> 
     sampler.addArgument(key,value);
    }
相关问题