0

I am new to RESTful services testing and got stuck where to establish connection to end point I need to pass Cookie. I have the parameter and Value but not sure how to pass Cookie manually (not through header or Groovy script) while hitting request.

so-random-dude
  • 15,277
  • 10
  • 68
  • 113
Aditya
  • 457
  • 2
  • 8
  • 27
  • 1
    you want to pass cookie, but not in the header ? then where ? cookies is parameters which passed in the request header, in HTTP you pass any meta data trough the header – roy Sep 02 '18 at 09:44
  • sorry if my question was not clear. The application will check for Cookie with specific parameter and value . I have tried to pass the parameter and value from Header at Test Step request but that didn't work out. So wanna check how can I send it through ? – Aditya Sep 02 '18 at 10:21
  • This is totally dependant on what method you are using to hit the endpoint, as already explained cookies are no more than a HTTP header so if you are asking theoretically then that is the answer - if you are looking for a more *specific* answer then you need to *be* more specific. – James Sep 05 '18 at 21:30

2 Answers2

1

Just send the http header

Cookie: name=value

To the server

iPirat
  • 2,197
  • 1
  • 17
  • 30
1

TL;DR

Cookies are nothing but a header with a name cookie and header-value in a format name=value; anothername=anothervalue; yetanotherone=yetanothervalue;, as far as an http-request is concerned

Read On

From https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cookie

The Cookie HTTP request header contains stored HTTP cookies previously sent by the server with the Set-Cookie header.

The Cookie header is optional and may be omitted if, for example, the browser's privacy settings block cookies.

How to send Cookie

Just like any other header. Only condition is, Header name should be cookie and Header-value should be in name=value; anothername=anothervalue; yetanotherone=yetanothervalue; format.

Curl

curl -v --cookie "USER_TOKEN=my-most-secure-session-id" http://localhost:8080/

If you want your curl to read the cookie file and send it

use curl -c /path/to/cookiefile http://yourhost/

More here : https://curl.haxx.se/docs/http-cookies.html

How to send it using SoapUI

Sending cookie as request header in SOAP UI request for rest web service

Establish User session (Login) using chrome or firefox and goto the developer tab and copy the cookie value and send that along with your soapUI request as a header. (Congrats, you are hijacking your own session)

For any test that you need to pass the cookie around, in soapUI, go to the testcase options and turn on "maintain HTTP session".

http://www.soapui.org/soapui-projects/form-based-authentication.html

This is my google chrome developer tab which shows stackoverflow page's requestheaders

enter image description here

so-random-dude
  • 15,277
  • 10
  • 68
  • 113