Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Header Cookie "sid" value to a variable

Tags:

cookies

jmeter

I need to extract the "sid" value from Jmeter Cookie. Below is the sample jmeter header output

GET htts://example.for.com/apex/AppDashboard?jl=1`

Cookie Data:

oinfo=c3RhdHVzPURlbW8mdHlwZT0yJm9pZD0wMERRMDAwMDAwR0phQkc=; logouturl=https://example.for.com/Login; disco=Q:00DQ000000GJaBG:005Q000000NwS1U:1; autocomplete=1; sid=00DQ000000GJaBG!ARoAQPklHZykcaAaJkI9prEbHROxU2CzxRfMDGKwMGpv5rZYwOOKd_GRiVRiYVYRKFTzYk6Vg0Zu48vmM5FyFSRQ4ZPtvQzR; sid_Client=000000NwS1U000000GJaBG; clientSrc=204.14.239.161; oid=00DQ000000GJaBG; apex__eventId=a0kQ0000002FecHIAS

Request Headers:

Connection: keep-alive
Accept-Language: en-US,en;q=0.5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:26.0) Gecko/20100101 Firefox/26.0
Referer: htts://example.for.com/apex/SecureLanding?eventId=a0kQ0000002FecHIAS
Accept-Encoding: gzip, deflate
Host: example.for.com

I need to extract the "sid" value from the cookie.

like image 905
user3204829 Avatar asked Jan 17 '14 01:01

user3204829


2 Answers

One option is to use a regular expression extractor on the response headers. You can do this by right clicking on your HTTP Request > Add > Post Processor > Regular Expression Extractor. Fill out the fields accordingly:

  1. Response Field to check: Headers
  2. ReferenceName: SID_VALUE
  3. Regular Expression: sid=(.*);
  4. Template: $1$
  5. Match No.: 1

If the SID exists in the cookies in the response, you can access in in other samplers/tests/etc by referencing it as ${SID_VALUE}.

like image 114
jason.zissman Avatar answered Sep 27 '22 23:09

jason.zissman


Another simplier option is adding a HTTP Cookie Manager which automatically handles cookies. However you need to set CookieManager.save.cookies=true property either in jmeter.properties file or by passing a corresponding parameter to JMeter startup script i.e.

jmeter -JCookieManager.save.cookies=true

After that you'll see all the cookies as JMeter Variables. The easiest way to visualize them is using Debug Sampler and View Results Tree Listener

In your case you can access your sid cookie as

${COOKIE_sid}

Other cookies can also similarly be obtained as ${COOKIE_sidClient}, ${COOKIE_clientSrc}, etc.

like image 32
Dmitri T Avatar answered Sep 28 '22 01:09

Dmitri T