How to generate a cookie and send it in a request in Jmeter
Asked Answered
A

1

7

I am fairly new to Jmeter and hence having trouble figuring out the following: I am testing a web service that needs a valid cookie to be sent in header. I have an endpoint url against which the userid and password validates. How do I validate the credentials against the url and extract the cookie for the user and send it in header for the request in Jmeter?

Argument answered 12/10, 2016 at 23:55 Comment(0)
I
8

JMeter provides HTTP Cookie Manager which automatically handles cookies so in the majority of cases you don't need to do anything apart from adding the HTTP Cookie Manager to your Test Plan

However in some cases, i.e. in some CSRF implementations you need to add a request header holding previous response specific cookie value. In that case you should be acting like:

  1. Add the next line to user.properties file (lives in JMeter's "bin" folder

    CookieManager.save.cookies=true
    
  2. Restart JMeter to pick the property up. The above setting "tells" JMeter to store cookie values as JMeter Variables prefixed by COOKIE_. So for example if you have cookie with the name of foo you will be able to access its value as ${COOKIE_foo}
  3. Add HTTP Header Manager and set it up to send the desired header using ${COOKIE_foo} as a value (replace foo with your actual cookie name)

More detailed information: Using the HTTP Cookie Manager in JMeter

Ironware answered 13/10, 2016 at 4:27 Comment(1)
With Jmeter version 3+, these steps are not needed. Just add HTTP cookie manager to your plan and it will automatically add cookie returned in the first HTTP request to the rest of HTTP requests.Alaska

© 2022 - 2024 — McMap. All rights reserved.