1

Curl's "cookie engine" gets enabled when you use --cookie. e.g. to let curl understand cookies from a page and follow a location (and thus send back cookies it received):

curl --cookie nada --location http://www.example.com

But how do you read cookies received? Tried:

curl -L -b cookies.txt http://example.com
curl --cookie-jar - https://gmail.com

curl --cookie cookies.txt --cookie-jar newcookies.txt http://www.example.com

curl --cookie-jar - https://gmail.com

Record cookies with curl by using --dump-header (-D) :

curl --dump-header headers_and_cookies http://www.example.com

but where is cookies.txt? Cookies are sent as HTTP headers, but I don't see it there. How do we see the outputs?

It was said that --cookie-jar or -c is a better way to store cookies, Curl has cookie parsing engine built-in that comes in use to reconnect to a server and use cookies that were stored from a previous connection but the cookie is not viewable. How can I access the file? It was also stated that it is possible to use previously stored cookies:

curl --cookie stored_cookies_in_file http://www.example.com

-c filename or --cookie-jar file name: Save cookies to file after a completed operation. Curl writes all cookies previously read from a specified file as well as all cookies received from remote server(s). If no cookies are known, no file will be written. To write to stdout, set the file name to a single dash, "-".

Ursa Major
  • 851
  • 7
  • 25
  • 47
  • I think you'll appreciate [this answer](https://stackoverflow.com/questions/7181785/send-cookies-with-curl/7186160#7186160). – Daniel Stenberg Jun 08 '17 at 06:00
  • I tried that. After issuing the command: >$ cat cookies.txt cat: cookies.txt: No such file or directory – Ursa Major Jun 08 '17 at 06:41
  • Then curl received no cookies?! – Daniel Stenberg Jun 08 '17 at 06:42
  • I think we have to pick a target to check if the cookies are issued by: >1. From the Chrome menu in the top right corner of the browser, select Settings. 2. At the bottom of the page, click Show advanced settings.... 3. Under Privacy, select Content settings.... 4. To manage cookie settings, view the options under "Cookies". – Ursa Major Jun 08 '17 at 07:02

1 Answers1

2

You can use the same file to read and write to:

CF="cookie.txt"
curl -b       "$CF" -c           "$CF" http://www.example.com/
curl --cookie "$CF" --cookie-jar "$CF" http://www.example.com/
David Newcomb
  • 10,639
  • 3
  • 49
  • 62