【发布时间】: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