--cookie
和-b
是等同的,它們只是指定文件來讀取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標頭或網景/ Mozilla瀏覽器cookie文件格式。
我使用的文件是Netscape cookie文件。
謝謝。它寫道,但沒有閱讀。 – Tom 2014-09-12 22:47:44
我不知道爲什麼,它適用於我。我可以在'Cookie:'請求標頭中看到Cookie。 – Barmar 2014-09-12 22:52:43
你能顯示你的輸出嗎?順便說一句,如果我不使用該文件,它對我來說很有用。 – Tom 2014-09-12 22:54:29