0

I m managing to pass cookie data with html cookie manager to http requests when they are get request but my post request stays with [no cookies] even if the html cookie manager is set.

the configuration is :

one post request and one redirect to a get request that sets the manually provided cookie. the manually provided cookie is supposed to be used in the first post request...

How can i do to pass the cookie to the post request?

thank you

2 Answers2

0

I have found a workaround:

I pass cookie value to the http header manager with Name Cookie and value to the cookies values separated by a ;

It's not very practical because if you want to reuse a cookie variable set by a previous thread group for a csrf authentication, you cant use variable in headers (see : https://stackoverflow.com/a/44463142 : HTTP Header Manager initializes before any thread starts, so you can't use variables there for that reason too.)

So you have to use BeanShell postprocessor in the first thread group and add :

${__setProperty(property_name, ${COOKIE_cookie_name})};

And then pass property_name to the cookie value to second thread group in the http header manager with Name : Cookie and value :

cookie_name=${__property(property_name)};
0

It's sufficient to add a HTTP Cookie Manager to your test plan and it will automatically handle cookies.

What it does is:

  1. Extracts cookies from Set-Cookie header and stores them internally
  2. On next request if there is a match in domain and path and cookie is not expired it sends the relevant cookie(s) via Cookie header

If you're not seeing the cookies for the second request it might be caused by one of the following reasons:

  1. You're not receiving any cookies from the server, i.e. your login attempt fails somehow, inspect request and response details using View Results Tree listener and ensure that your test is doing what it is supposed to be doing

  2. There is a problem with the cookie you're receiving from the server, i.e. domain/path mismatch or expiration date issue, you can enable debug logging for the HTTP Cookie Manager, it can be done by adding the next line to log4j2.xml file:

    <Logger name="org.apache.jmeter.protocol.http.control" level="debug" />
    

    and after JMeter restart you should see verbose information regarding incoming and outgoing cookies in jmeter.log file

More information: HTTP Cookie Manager Advanced Usage - A Guide

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • that works for recursive requests, but what about cookies set for the first request? –  Jul 14 '22 at 09:26
  • JMeter starts "clean" user, it means there will no be any cookies sent with the first request. – Dmitri T Jul 14 '22 at 09:59