我试图将令牌从第一个请求的responseHeader 传递到循环中的后续请求。但是,我不断收到错误消息,指出“continuationToken”(如示例中所示)未定义
val httpProtocol = http
.baseUrl("some-base-url")
val scn = scenario("Scenario for 'Get store assortments by storeId'")
.exec(http("request_1")
.get("endpoint1")
.header("api-key","api-key")
.queryParam("param", true)
.check(header("continuationToken").saveAs("${continuationToken}")))
.doWhile(session => session("${continuationToken}").as[String] != null) {
exec(http("request_2")
.get("endpoint1")
.header("api-key", "api-key")
.queryParam("param", true)
.queryParam("continuationToken", "${continuationToken}")
.check(header("continuationToken").saveAs("${continuationToken}")))
}
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
错误:
================================================================================
---- Global Information --------------------------------------------------------
> request count 1 (OK=0 KO=1 )
> min response time 129 (OK=- KO=129 )
> max response time 129 (OK=- KO=129 )
> mean response time 129 (OK=- KO=129 )
> std deviation 0 (OK=- KO=0 )
> response time 50th percentile 129 (OK=- KO=129 )
> response time 75th percentile 129 (OK=- KO=129 )
> response time 95th percentile 129 (OK=- KO=129 )
> response time 99th percentile 129 (OK=- KO=129 )
> mean requests/sec 1 (OK=- KO=1 )
---- Response Time Distribution ------------------------------------------------
> t < 800 ms 0 ( 0%)
> 800 ms < t < 1200 ms 0 ( 0%)
> t > 1200 ms 0 ( 0%)
> failed 1 (100%)
---- Errors --------------------------------------------------------------------
> status.find.in([200, 209], 304), found 400 1 (50.00%)
> request_2: Failed to build request: No attribute named 'contin 1 (50.00%)
uationToken' is defined
================================================================================
您的
request_1
请求失败:status.find.in([200, 209], 304), found 400
。
因此,它无法成功捕获预期的标头:它很可能仅在请求成功并返回 200 时才出现。
降低 logback conf 文件中的日志记录级别,检查您的负载,然后找出服务器响应“400:错误请求”的原因。