【问题标题】:Add dynamic number of parameters to http sampler向http采样器添加动态数量的参数
【发布时间】:2016-09-13 04:18:16
【问题描述】:

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

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

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

我成功设置了 HOST,PORT,PATH,HEADERS..

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

下面是我将 json 内容从 json parser 解析为 jsonparser 的 groovy 代码,我正在设置上面的 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 ));
}
}

【问题讨论】:

    标签: jmeter


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-06
      • 2018-09-24
      • 2014-01-29
      • 2019-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多