# Need help passing cookies (detailed problem description with pictures)

**URL:** <https://forum.katalon.com/t/need-help-passing-cookies-detailed-problem-description-with-pictures/14042>\
**Category:** API Testing\
**Tags:** api-testing, katalon-studio\
**Created:** [October 31, 2018, 11:49am UTC](https://forum.katalon.com/t/need-help-passing-cookies-detailed-problem-description-with-pictures/14042 "2018-10-31T11:49:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Reijling](https://avatars.discourse-cdn.com/v4/letter/p/2acd7d/32.png) [@Paul\_Reijling](https://forum.katalon.com/u/Paul_Reijling)\
**Post date:** [October 31, 2018, 11:49am UTC](https://forum.katalon.com/t/need-help-passing-cookies-detailed-problem-description-with-pictures/14042/1 "2018-10-31T11:49:05Z")

</div>

I’m trying out Katalon and am using the REST API of Microfocus ALM. It requires me to start with a POST Authentication Request:

![](https://s3.amazonaws.com/katalon-forum/editor/l1/qj3vubb2qo53.png "Image: https://s3.amazonaws.com/katalon-forum/editor/l1/qj3vubb2qo53.png")  
When I run this request the raw header is:  
 ![](https://s3.amazonaws.com/katalon-forum/editor/8x/vdno5cv17v24.png "Image: https://s3.amazonaws.com/katalon-forum/editor/8x/vdno5cv17v24.png")

So far so good. Subsequently I need to do a GET request for a session:

![](https://s3.amazonaws.com/katalon-forum/editor/oy/6ocj4t4pjmsr.png "Image: https://s3.amazonaws.com/katalon-forum/editor/oy/6ocj4t4pjmsr.png")

I’m trying to pass the cookie using a Global variable. The script is:  
 ![](https://s3.amazonaws.com/katalon-forum/editor/6f/astlu9d4upuj.png "Image: https://s3.amazonaws.com/katalon-forum/editor/6f/astlu9d4upuj.png")  
In this code I’m encoding the cookie values, but I have tried without encoding as well. The result (after sending the request) however is:  
 ![](https://s3.amazonaws.com/katalon-forum/editor/53/h0ibtkgclmke.png "Image: https://s3.amazonaws.com/katalon-forum/editor/53/h0ibtkgclmke.png")  
I’ve tried a number of different approaches, but all of them fail. What should I do? If I cannot get this simple chain of requests to work properly Katalon is of no use, but I cannot believe that to be the case.

Please help.

[Katalon\_01.PNG](https://s3.amazonaws.com/katalon-forum/editor/l1/qj3vubb2qo53.png)

[Katalon\_02.PNG](https://s3.amazonaws.com/katalon-forum/editor/8x/vdno5cv17v24.png)

[Katalon\_03.PNG](https://s3.amazonaws.com/katalon-forum/editor/oy/6ocj4t4pjmsr.png)

[Katalon\_04.PNG](https://s3.amazonaws.com/katalon-forum/editor/6f/astlu9d4upuj.png)

[Katalon\_05.PNG](https://s3.amazonaws.com/katalon-forum/editor/53/h0ibtkgclmke.png)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [October 31, 2018, 12:21pm UTC](https://forum.katalon.com/t/need-help-passing-cookies-detailed-problem-description-with-pictures/14042/2 "2018-10-31T12:21:02Z")

</div>

```auto
list.each {
    cookiesstring = cookiesstring + UrlEncoder.encode("$it") + ";"
}

```

Could you tell us the full package name of UrlEncoder class? I have never seen UrlEncoder class (I know java.net.URLEncoder though).

Also would you check how the UrlEncoder.encode("$it") works by inserting a debug print:

```auto
list.each { println "Cookie: \'${it}\' => \'${UrlEncoder.encode(\"${it}\")}\'" cookiesstring = cookiesstring + UrlEncoder.encode("$it") + ";"}

```

---

<div class="post-metadata">

**Author:** ![Paul\_Reijling](https://avatars.discourse-cdn.com/v4/letter/p/2acd7d/32.png) [@Paul\_Reijling](https://forum.katalon.com/u/Paul_Reijling)\
**Post date:** [October 31, 2018, 1:32pm UTC](https://forum.katalon.com/t/need-help-passing-cookies-detailed-problem-description-with-pictures/14042/3 "2018-10-31T13:32:59Z")

</div>

import com.kms.katalon.core.webservice.support.UrlEncoder  
Encode result: klm\_tracking\_id%3D82301158\_172.30.17.3%3BPath%3D%2F%3BDomain%[3D.klm.com](http://3D.klm.com)%3BVersion%3D1%3BSecure%3BHttponly;sticky-key%3D%21vIDOvtcawzBAeVVW3nsCaOopaCNVQhXdyUTdyFz%2FI%2FzWP4rXHySoQoapjSYRzXePf8df8POXFNwuaLU%3D%3B+path%3D%2F%3B+Httponly%3B+Secure;XSRF-TOKEN%3D0ed9b1fd07b0bc232503b961044b48373e2ee030b9cb8f1efb49f586668ddf72%3BPath%3D%2F;ALM\_USER%3D182638537d46f141d72619e548122fa5e597a312e34a3e20ed282ecba792435e%3BPath%3D%2F%3BSecure;QCSession%3DNzA5MDg1MztVVHg0V296VjFHT3pObnZtVDF4M0V3Kio7UkVTVCBjbGllbnQ7IDsg%3BPath%3D%2F%3BSecure%3BHttpOnly;LWSSO\_COOKIE\_KEY%3DEftB17ny37KyfOEwP6LHscYW65ggSuwPLlpUCR-8iCqYq00m69FDFYFJXX6ZXdZAlZo3dmQgH-ul–3kBaiDMYZ45ahcN2YFD3HjpA-FoXiJYMPFxXKc2P8ZwV1nJ-b4WDp0jCuhdXlsstavTchhjvYI7gdlZvt93DldfITbjRItLrhlFIzOXUrHtil1hC1AjlRpHuGEYZNVJnsY44hLY92JPFknyZktecJPkmY7WXDldoFJimNk\_jdCuTtcMVNNwGe1Jlneq4x\_vKSjmCQ4IcbsP\_Aw0ohyuC1QqCGsB9U.%3BPath%3D%2F%3BHTTPOnly;

---

<div class="post-metadata">

**Author:** ![Paul\_Reijling](https://avatars.discourse-cdn.com/v4/letter/p/2acd7d/32.png) [@Paul\_Reijling](https://forum.katalon.com/u/Paul_Reijling)\
**Post date:** [November 1, 2018, 8:40pm UTC](https://forum.katalon.com/t/need-help-passing-cookies-detailed-problem-description-with-pictures/14042/4 "2018-11-01T20:40:37Z")

</div>

I’ve managed to solve my problem. No need to encode cookie values after all. I’ve split the cookies from the first response into name/value pairs and add them to the cookie header from the next request one by one thereby omitting the first 2 cookies (in this case klm\_tracking\_id and sticky-key cookie), after that it worked perfectly and getting the needed JSESSIONID cookie from the response needed for my 3rd API request.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [November 1, 2018, 8:47pm UTC](https://forum.katalon.com/t/need-help-passing-cookies-detailed-problem-description-with-pictures/14042/5 "2018-11-01T20:47:04Z")

</div>

Glad to hear it.

Would you agree to ask the Katalon Forum moderators to bring this post to CLOSED status?

---

<div class="post-metadata">

**Author:** ![Paul\_Reijling](https://avatars.discourse-cdn.com/v4/letter/p/2acd7d/32.png) [@Paul\_Reijling](https://forum.katalon.com/u/Paul_Reijling)\
**Post date:** [November 2, 2018, 1:07pm UTC](https://forum.katalon.com/t/need-help-passing-cookies-detailed-problem-description-with-pictures/14042/6 "2018-11-02T13:07:15Z")

</div>

Yes post can be closed

---

<div class="post-metadata">

**Author:** ![surajigure09](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/surajigure09/32/16103_2.png) [@surajigure09](https://forum.katalon.com/u/surajigure09)\
**Post date:** [October 16, 2020, 7:02am UTC](https://forum.katalon.com/t/need-help-passing-cookies-detailed-problem-description-with-pictures/14042/7 "2020-10-16T07:02:33Z")

</div>

Hi @Paul_Reijling

Could you please post the solution of splitting cookies and how u used it. thanks !

---

<div class="post-metadata">

**Author:** ![Paul\_Reijling](https://avatars.discourse-cdn.com/v4/letter/p/2acd7d/32.png) [@Paul\_Reijling](https://forum.katalon.com/u/Paul_Reijling)\
**Post date:** [October 26, 2020, 6:39am UTC](https://forum.katalon.com/t/need-help-passing-cookies-detailed-problem-description-with-pictures/14042/8 "2020-10-26T06:39:30Z")

</div>

`class` `CookieMonster {`

` ` `@Keyword`

` ` `static` `getCookies(ResponseObject response) {`

` ` `// Get the contents of the 'Set-Cookie'`

` ` `def cookiez = (response.getHeaderFields()[` `'Set-Cookie'` `])`

` ` `def name = []`

` ` `def value = []`

` ` `def items = ` `0`

` ` `def cookiesstring = ` `''`

` ` `def pair`

` ` `cookiez.each({ def cookies ->`

` ` `pair = cookies.split(` `'='` `)`

` ` `name.add(pair[` `0` `])`

` ` `value.add(pair[` `1` `])`

` ` `items++`

` ` `})`

` ` `// Get cookie names and values to a string omitting unwanted cookies`

` ` `for` `(` `int` `i = ` `0` `; i != items; i++) {`

` ` `if` `(((name[i]) != ` `'name_of_unwanted'` `) && ((name[i]) != ` `'name_of_unwanted'` `)) {`

` ` `cookiesstring = ((((cookiesstring + (name[i])) + ` `'='` `) + (value[i])) + ` `';'` `)`

` ` `}`

` ` `}`

` ` `cookiesstring.substring(` `0` `, cookiesstring.length() - ` `1` `)`

` ` `return` `cookiesstring`

` ` `}`

`}`

---

<div class="post-metadata">

**Author:** ![surajigure09](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/surajigure09/32/16103_2.png) [@surajigure09](https://forum.katalon.com/u/surajigure09)\
**Post date:** [December 11, 2020, 6:15am UTC](https://forum.katalon.com/t/need-help-passing-cookies-detailed-problem-description-with-pictures/14042/9 "2020-12-11T06:15:04Z")

</div>

Thank you !

---

<div class="post-metadata">

**Author:** ![albert.vu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/albert.vu/32/20595_2.png) [@albert.vu](https://forum.katalon.com/u/albert.vu)\
**Post date:** [August 8, 2022, 7:31am UTC](https://forum.katalon.com/t/need-help-passing-cookies-detailed-problem-description-with-pictures/14042/10 "2022-08-08T07:31:45Z")

</div>

Archived on August 8, 2022, 7:31am UTC


