How extract part of requests header

Hi All.
How I can extract part of requests header - RequestVerificationToken. There is my code

import io.gatling.http.Predef._
import io.gatling.core.structure.ChainBuilder

object MainPage {
val headers_0 = Map(


val OpenMainPage: ChainBuilder = exec {
.check(headerRegex(“Cookie”, “RequestVerificationToken=([a-zA-z0-9_-]+)”).saveAs(“requestVerificationToken”))}

.exec(session => session.set(“requestVerificationToken”, session(“requestVerificationToken”).as[String]))

When I run my simulation I get next error message - “[ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - ‘hook-4’ crashed with ‘j.u.NoSuchElementException: No attribute named ‘requestVerificationToken’ is defined’, forwarding to the next one”


Are you sure your check is correct?
Try to add an exitHereIfFailed between both exec.

I guess that regex matches the whole header.

val OpenMainPage: ChainBuilder = exec {
.check(headerRegex("Cookie", ".*RequestVerificationToken=([a-zA-z0-9_-]+).*").saveAs("requestVerificationToken"))}

Hope this helps,

I checked my regex. The test shows that everything is working correctly.

четверг, 2 декабря 2021 г. в 15:48:29 UTC+3,

First, checks are applied on responses, not requests. You’re the one crafting the requests.

Then, Gatling automatically deals with sending the Cookie headers to the server, as long as you’ve properly populated the CookieJar:

  • either automatically with the responses containing a Set-Cookie header,
  • or manually with addCookie.

Now, you have to figure out where this Cookie comes from in your actual application? Is it set by the server, or by the client with JavaScript?