问题是:如何发送具有内容类型表单数据的主体的请求,并且此请求主体应包含先前响应中保存的参数
代码为:
TestPlanStats stats = testPlan(
threadGroup(1, 1),
httpSampler(firstRequestUrl)
.method(POST)
.contentType(APPLICATION_JSON)
.header(AUTHORIZATION, getToken())
.body(someBody)
.children(new DslJsr223PostProcessor("Get param",
"def jsonResponse = new groovy.json.JsonSlurper().parseText(prev.getResponseDataAsString())\n" +
"def paramValue = jsonResponse.param\n" +
"vars.put('paramKey', paramValue)")),
httpSampler(secondRequestUrl)
.method(POST)
.contentType(MULTIPART_FORM_DATA)
.body(here need to provide form body with "${paramKey}")
.children(new DslJsr223PostProcessor("Get response status code",
"int statusCode = prev.getResponseCode();\n" +
"vars.put('responseStatusCode', String.valueOf(statusCode));"
)),
new DslJsr223Sampler("Print result",
"String result = vars.get('responseStatusCode');" +
"if (result != null) {\n" +
" println('csrfKey: ' + result);\n" +
"} else {\n" +
" println('result not found');\n" +
"}")
).rampTo(testParams.getThreads(), Duration.ofMinutes(testParams.getRumpUpTime())),
influxDbListener(envSetting.getInfluxDbUrl())
.measurement("someMeasurement")
).run();
从第一个httpSampler()开始,我将参数保存到JMetervarsMap中。
在第二个httpSampler()中,我需要发送一个内容类型为Form-data的请求,该请求应包含保存在JMeter varsMap中的参数“${paramKey}”
请求体应包含参数:
- param1 =“${paramKey}”
- 参数2 = 10.01
- param3 =“SomeText1”
- param4 = false
- param5.key1 = 11111
- param5.key2 =“SomeText2”
- param5.key3 = 22222
方法body(Function<PreProcessorVars, String> bodySupplier)
或body(String body)
的签名。
如何用这些需求构建一个合适的请求体?
1条答案
按热度按时间dgenwo3n1#
例如:
将生成如下所示的HTTP请求采样器:
更多信息请参阅: