下午好。在 Gatling 文档中有点困惑,我找不到解决方案。我想获得一个令牌以在另一种方法中用作标头。这是我获得令牌的第一种方法的示例:
exec(
http("HTTP Request auth")
.post("http://blabla:9001/connect/token")
.header("Content-Type","application/x-www-form-urlencoded")
.formParam("grant_type","password")
.formParam("username", "${login}")
.formParam("password", "${password}")
.formParam("client_id","ro.client")
.formParam("client_secret","secret")
.check(status is 200)
.check(header("access_token").saveAs("access_token"))
.check(header("token_type").saveAs("token_type"))
)
这是第二种方法,我想传递令牌:
.exec(
http("HTTP Request createCompany")
.post("/Companies/CreateCompany")
.header("Authorization","${token_type} + ${access_token}")
.check(status is 200)
)
结果,写道找不到令牌:
Request:
HTTP Request auth: KO header(access_token).find(0).exists, found nothing
但随后他写道:
body={"access_token":"7e8c1d997dd92f16a87fa7ffb8a88ab14eb05a8883d78fe8652d072f24b5ca4a","expires_in":31536000,"token_type":"Bearer"}
我想我在这里发现错了:
.check(header("access_token").saveAs("access_token"))
.check(header("token_type").saveAs("token_type"))