Tom
Tom

Reputation: 363

curl no cookie set, no cookie save

I am running curl to test cookies

curl -v --cookie cookies.txt -b cookie_to_del http://localhost/

There is no cookie_to_del file appear, but in output I see:

* Added cookie TestCookie="my+cookie+value" for domain localhost, path /, expire 0
< Set-Cookie: TestCookie=my+cookie+value

Same way, in cookies.txt I have several cookies and do not see them set-up. My server has php command print_r($_COOKIE); and I shows empty array.

What's wrong?

Upvotes: 0

Views: 7883

Answers (1)

Barmar
Barmar

Reputation: 782166

--cookie and -b are equivalent, they just specify the file to read cookies from. It won't create or overwrite this file. And if you give them multiple times, only the last one is used.

To save cookies, you have to use --cookie-jar or -c. So it should be:

curl -v --cookie cookies.txt --cookie-jar cookie_to_del http://localhost

If you want to update your original cookies with the cookies sent back, you can use the same file with both otions.

My `cookies.txt` file contains:

# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

.bridgebase.com TRUE    /   FALSE   0   SRV www3

And I do:

$ curl -s -v --cookie cookies.txt --cookie-jar cookies_to_del http://www.bridgebase.com/vugraph/schedule.php >/dev/null
* About to connect() to www.bridgebase.com port 80 (#0)
*   Trying 65.254.56.174... connected
* Connected to www.bridgebase.com (65.254.56.174) port 80 (#0)
> GET /vugraph/schedule.php HTTP/1.1
> User-Agent: curl/7.21.4 (x86_64-apple-darwin10.8.0) libcurl/7.21.4 OpenSSL/0.9.8y zlib/1.2.3 libidn/1.20
> Host: www.bridgebase.com
> Accept: */*
> Cookie: SRV=www3
> 
< HTTP/1.1 200 OK
< Server: nginx/1.6.0
< Date: Fri, 12 Sep 2014 22:55:29 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: close
< Vary: Accept-Encoding
< X-Powered-By: PHP/5.4.26-0
* Added cookie PHPSESSID="gu1fj84buirg370lee356b5r26" for domain www.bridgebase.com, path /, expire 0
< Set-Cookie: PHPSESSID=gu1fj84buirg370lee356b5r26; path=/; HttpOnly
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Pragma: no-cache
< Cache-control: private
< 
{ [data not shown]
* Closing connection #0

As you can see, it sent the header Cookie: SRV=www3, which it read from the file. The resulting cookies_to_del file contains:

# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

.bridgebase.com TRUE    /   FALSE   0   SRV www3
#HttpOnly_www.bridgebase.com    FALSE   /   FALSE   0   PHPSESSID   gu1fj84buirg370lee356b5r26

Regarding the format of the file, the documentation says:

The file format of the file to read cookies from should be plain HTTP headers or the Netscape/Mozilla cookie file format.

The files I used are Netscape cookie file.

Upvotes: 2

Related Questions