Gatling - 从响应头中提取令牌

时间:2021-05-06 18:05:55

标签: gatling

我是 Gatling 的新手,我创建了一个 POST 登录请求,该请求返回以下响应标头:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">

<deployment>
<dependencies>

<module name="com.sun.xml.bind" />

</dependencies>
</deployment>
</jboss-deployment-structure>

我需要提取 JSESSIONID 值并在其他请求中使用它。 我试过了:

HTTP/1.1 302 
Set-Cookie: JSESSIONID=ECA5F6FEA172B13BF5D445399C9C0962; Path=/; HttpOnly
Location: http://localhost:20001/index;jsessionid=ECA5F6FEA172B13BF5D445399C9C0962
Content-Language: en-US
Content-Length: 0
Date: Thu, 06 May 2021 16:01:20 GMT

但是出现错误

.check(regex("JSESSIONID=(.*?);").find.saveAs("token")))

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

您需要使用 headerRegex

.check(headerRegex("Set-Cookie", """JSESSIONID=(.*?);"""").saveAs("token"))