Search code examples
jmeterjmeter-5.0

Capture Cookie from Response Header in Login and use it to all subsequent steps in Request Headers


I cannot modify anything on user.properties to add next line CookieManager.save.cookies=true because I run my scripts from a remote machine in which I don't have access to.

I am able to capture the Cookie using a Regular Expression Extractor from RESPONSE HEADER in Login and save it in a variable 'Cookie_cp'. I tried adding 'Cookie_cp' on HTTP Cookie Manager and also tried adding it on HTTP Header Manager, but JMeter sends the cookie only on REQUEST BODY, but not the REQUEST HEADER.

Another issue is that 'Cookie_cp' is being captured from second step's RESPONSE HEADER and applied to third step, while I need this cookie to be applied only from Login to all other steps.

Any help please?


Solution

  • JMeter sends the cookie(s) in the Cookie header, not in the request body, if you're using View Results Tree listener to inspect the request and it shows the cookie in the "Request Body" tab it's kind of misleading.

    In fact JMeter does send the cookie(s) in the Cookie header, you can double check it using a sniffer tool like Wireshark

    enter image description here

    If you want to send the cookie (or any other header) with all the requests starting from second one you can:

    1. Put these requests under a Simple Controller
    2. Add HTTP Cookie Manager (or HTTP Header Manager) at the same level as these requests

    Both Cookie and Header manager obey JMeter Scoping Rules so the header(s) will be added to all Simple Controller's children

    enter image description here