title: Not able to extract values in Gatling
body: <p>I have written 2 sets of Gatling code. My usecase in example 1 is make a post call. extract a value. make a get call and use the extracted value in header.</p>
  
  <p>My usecase in example 2 is make a post call, extract a value, make a get call use the extracted value in cookie.</p>
  
  <h2>Example 1</h2>
  
  <pre><code>   val login = http("Login")
        .post("login")
        .body(StringBody("""{"username": "foo", "password": "bar"}""")).asJSON
        .check(status.is(200), jsonPath("$..response.id").ofType[String].saveAs("id"))
  
     val get = http("get")
        .get("foo")
        .header("token", "$id")
        .check(status.is(200), jsonPath("$..response").exists)
  
     var id = ""
     val scn = scenario("scenario")
        .exec(login)
        .exec(session =&gt; {
           id = session("id").as[String].trim
           println("+++++++" + id)
           session}
        )
        .pause(3)
        .exec(get)
  </code></pre>
  
  <p>When I run this code I see that the print statement above prints the correct ID. The server throws 403 on the get call because the ID is not being set correctly. If I take any of the printed values and then remote <code>$id</code> and replace it with that. the test runs correctly. </p>
  
  <p>So how do I access the saved variable?</p>
  
  <h2>Example 2</h2>
  
  <pre><code>val login = http("Login")
        .post("login")
        .body(StringBody("""{"username": "foo", "password": "bar"}""")).asJSON
        .check(status.is(200), jsonPath("$..response.id").ofType[String].saveAs("id"))
  
     val get = http("get")
        .get("foo")
        .check(status.is(200), jsonPath("$..response").exists)
  
     val testCookie = scenario("test-cookie")
        .exec(login)
        .pause(3)
        .exec(addCookie(Cookie("foo_cookie", "$id")))
        .exec(get)
  </code></pre>
  
  <p>Here also the value is not extracted successfully and I get a 403 when I run it because the "foo_cookie" was not set correctly and the server will throw a 403 if the cookie is not found. (in postman I can make the same call work by specifying the cookie correctly)</p>