如何在加特林中检索响应标头并多次执行http调用? [英] How to retrieve response headers in gatling and execute http call multiple times?
问题描述
我正在尝试找到一种方法,以从http调用响应中获取响应标头,例如X-RateLimit-Limit,X-RateLimit-Remaining等. 找不到在线资源或文档,有人可以帮忙吗? 启用日志记录后,我在控制台中看到了这些标头,但不知道如何从响应中检索这些标头.
I'm trying to find a way to get response headers such as X-RateLimit-Limit, X-RateLimit-Remaining etc. from http call response. Not able to find from online resources or documentation, can someone help? I see these headers in console as I enabled logging but don't know how to retrieve these headers from response.
http("Get API")
.get("https://hello.com/list")
.header("Authorization", "${auth}")
.check(status.is(200))
.check(bodyString.saveAs("Auth_Response"))
还有一种方法可以在一个时间范围内多次运行此http调用.我应该使用哪些内置方法来循环以及在特定时限内运行此特定的http调用?我在下面尝试过但未成功.理想情况下,我希望能够验证此API速率限制,因此可以尝试这种方式.虽然我逐渐了解到我不能同时使用repeat()duration(),但是它们具有两个我要实现的不同目的.即使只是在duration()中调用http请求构建器类型调用也会引发错误-"它与预期的ChainChainer类型不符"
Also is there a way to run this http call multiple times within a timeframe. What in-built methods should i use for looping as well running this specific http call within certain time limit? I tried below but unsuccessful. Ideally I would want to be able to verify this APIs rate limit hence tried this way. Although I'm getting to understand that I can't use repeat() duration() both at the same time however they serve 2 different purpose which I want to achieve. Even just calling http request builder type call in duration() is throwing error - "it doesn't conform to expected type ChainBuilder"
val scn1 =
during (60.seconds) {
scenario("Setup scenario")
.repeat(201){
exec(
http("Get API")
.get("https://hello.com/list")
.header("Authorization", "${auth}")
)}
setUp(
scn1.inject(
atOnceUsers(1)
)
)
}
无论我在setup()期间放置setup()还是在其外部放置,都会导致错误.我正在尝试评估我是否甚至需要after().仅使用repeat(201)时,它会导致API运行201次并减少api的X-RateLimit-Remaining
计数,但不足以达到0导致错误代码回复.
请提供建议吗?
Whether I put setup () inside during() or outside, its causing error. I am trying to evaluate if I even need during().When using just repeat(201) it causing the API to run 201 times and reducing the count of X-RateLimit-Remaining
for api however not enough to reach it to 0 causing the error code response.
Kindly provide any suggestions?
推荐答案
位于备忘单上,位于 .check(header(headerName)).is(...)
.check(header(headerName)).is(...)
这篇关于如何在加特林中检索响应标头并多次执行http调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!