--cookie 和 -b 是等价的,它们只是指定要从中读取 cookie 的文件。它不会创建或覆盖此文件。如果你给他们多次,只有最后一个被使用。
要保存 cookie,您必须使用 --cookie-jar 或 -c。所以应该是:
curl -v --cookie cookies.txt --cookie-jar cookie_to_del http://localhost
如果您想使用发回的 cookie 更新您的原始 cookie,您可以使用同一个文件进行这两个选项。
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
我愿意:
$ 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
如您所见,它发送了从文件中读取的标头Cookie: SRV=www3。生成的cookies_to_del 文件包含:
# 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
关于文件的格式,文档说:
要从中读取 cookie 的文件的文件格式应该是纯 HTTP 标头或 Netscape/Mozilla cookie 文件格式。
我使用的文件是 Netscape cookie 文件。