# Session Usage in gatling

**URL:** <https://community.gatling.io/t/session-usage-in-gatling/2129>\
**Category:** Gatling (Open-Source)\
**Created:** [March 20, 2015, 4:04pm UTC](https://community.gatling.io/t/session-usage-in-gatling/2129 "2015-03-20T16:04:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohit\_Garg](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mohit\_Garg](https://community.gatling.io/u/Mohit_Garg)\
**Post date:** [March 20, 2015, 4:04pm UTC](https://community.gatling.io/t/session-usage-in-gatling/2129/1 "2015-03-20T16:04:38Z")

</div>

How to use session in Gatling?

Lets say my application is returning an token in a response so how to save that token from url.

I know that we can use session but I have no idea how to do that.

Please help in writing the .scala file for above scenario?

---

<div class="post-metadata">

**Author:** ![Gregory\_Melekh](https://avatars.discourse-cdn.com/v4/letter/g/ecccb3/32.png) [@Gregory\_Melekh](https://community.gatling.io/u/Gregory_Melekh)\
**Post date:** [March 22, 2015, 8:37am UTC](https://community.gatling.io/t/session-usage-in-gatling/2129/2 "2015-03-22T08:37:29Z")

</div>

You can do it like this:

http(“doLogin”)

.post("/sign\_in")  
.formParam(""“user[login]”"", “”“gatling”"")

.formParam(""“user[password]”"", “”“123456"”")

.formParam("""…""","""…""")  
.

.check(regex("""\<meta content="(.\*?)" name=“csrf-token”"").saveAs(“token”))

---

<div class="post-metadata">

**Author:** ![Mohit\_Garg](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mohit\_Garg](https://community.gatling.io/u/Mohit_Garg)\
**Post date:** [March 24, 2015, 1:24pm UTC](https://community.gatling.io/t/session-usage-in-gatling/2129/3 "2015-03-24T13:24:32Z")

</div>

Thanks Gregory ,

I am trying to do so. But I am getting some error. Can you verify me again with correct syntax to extract a parameter from response url. Now I need to fetch two parameters and how to print them in my simulation script.

Please help me?
