Ask a Question

Maintain HTTP Session: Should pass cookies to following request

Occasional Contributor

Maintain HTTP Session: Should pass cookies to following request

Hi, I was reading this community forum for a long time about maintaining https session over several requests.

But I'm not able to run it sucessfully.


I'm on Ready!API 1.5.0  (SoapUI NG Pro) Build Date: 20151106-1037


All I want to do is

1.) Request A contains in its response 3 cookies (within the http header)

2.) I would like to have this 3 cookies transfered in Request B (also in the http header)


It's as simple, but it doesn't work.

I tried:  to pass the cookie around, go to the testcase options and turn on "maintain HTTP session".

Simply enable this option to true does not work

I also tried to use a property transfer, but how can I easily pass all cookies?

I don't want to write groovie code. I think such basic requirement should be handled by the tool itself.


Maybe someone has an idea?



Regards, Reto

SmartBear Alumni (Retired)

Hi Reto,


You should see your cookies in Get Data (right-click the mouse in the request editor and select Get Data from the context menu). Did you try it?

Tanya Yatskovskaya
SmartBear Community and Education Manager

Occasional Contributor

Hi Tanya

Where exactly do you mean to use the "get Data" for the http header?


I have a REST request.

On the Request Window:

a) I can manually add headers on the "Headers" tab - but this is a dialog, no "get Data".

b) In the outline section, there is the request body, not the header, "get Data" would work there, but makes no sense because I would like to set http headers.



Regards, Reto

In your REST request, you should add those 3 header fields (you don't need to supply a value):



Then in the actual test step, double click the value field of each, right-click, then use 'Get Data' to get each header from the response of a previous request:


Occasional Contributor

Hi Justin

Thanks for that hint.

But it doesn't work in my case.


a) my first request contains in it's response:

Set-Cookie: JSESSIONID=xxxxxxxxxxxx; Path=/yyyyyyyyyyyyyyyy; Secure
Set-Cookie: WAF-XSRF-TOKEN=zzzzzzzzzzzzzzzz; Path=/
Set-Cookie: XSRF-TOKEN=aaaaaaaaaaaaaaaaa; Path=/
Access-Control-Allow-Headers: origin, content-type, accept, X-XSRF-TOKEN


b) I have to transfer those cookies to the next request


Now I try with a groovy script

Actually I think it would work, but it douplicates all cookies in the header, each time I start the script ??


def header = testRunner.testCase.getTestStepByName("firstLoginCookie").httpRequest.response.responseHeaders["Set-Cookie"]
 header=header.toString()" Current XSRF-TOKEN header: " + header)
 start=header.indexOf(" XSRF-TOKEN=")" Current XSRF-TOKEN start: " + start+1)

 end=header.indexOf("; Path=/]")" Current XSRF-TOKENend: " + end)

 testCaseProperty= header.substring(start+1,end)
 vXsrf=testCaseProperty"Current xsrf: " + vXsrf) 

////////////////" Current WAF-XSRF-TOKEN header: " + header)
 start=header.indexOf(" WAF-XSRF-TOKEN=")" Current WAF-XSRF-TOKEN start: " + start+1)

 end=header.indexOf("; Path=/, ")" Current WAF-XSRF-TOKEN end: " + end)

 testCaseProperty= header.substring(start+1,end)
 vWafXsrf=testCaseProperty"Current wafxsrf: " + vWafXsrf) 

////////////////" Current JSESSIONID header: " + header)
 start=header.indexOf("JSESSIONID=")" Current JSESSIONID start: " + start)

 end=header.indexOf("; Path=/com.avaloq")" Current JSESSIONID end: " + end)

 testCaseProperty= header.substring(start,end)
 vJsessionId=testCaseProperty"Current vJsessionId: " + vJsessionId) 

// Iterate through all test steps and add the session cookie to the headers.
for ( tstep in context.testCase.testSteps ) {
 testStepName = ( tstep.key )"Current testStepName: " + testStepName);

 if ( testStepName != 'firstLoginCookie' && testStepName != 'SetXSRFheadersForAll') {"Cookie set for " + testStepName)
 def headers=testRunner.testCase.testSteps[testStepName].testRequest.requestHeaders 
 headers.put('Cookie', vXsrf) 
 headers.put('Cookie', vWafXsrf)
 headers.put('Cookie', vJsessionId +'; Path=/; Secure')




Regards, Reto


Champion Level 3

Happened to write it some time ago for a forum request. Could not get that thread, but here is the script that you can try.


Also, do you have 'Maintain HTTP session' enabled for your test case? I believe that will handle passing your session amongst the test steps.


Nevermind, I see you've already done that

Occasional Contributor

Thanks to all of you

Adding all this informations together, I could solve my problem.

Now I use  the groovy script to extract the cookie values and a project property to write it into.

In the following request I just need to read out this project property in the header values XSRF-TOKEN=${#Project#XSRF-TOKEN_PROPERTY}



Regards, Reto

Occasional Contributor

What if I have two Set-cookie parameters in the header? Could you please tell me how should I get second one?

Here is a picture what I have:

Showing results for 
Search instead for 
Did you mean: