[英]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: 没有出现
cookie_to_del
文件,但是在输出中我看到:
* 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. 同样,在cookies.txt中,我有几个cookie,但看不到它们的设置。 My server has php command
print_r($_COOKIE);
我的服务器上有php命令
print_r($_COOKIE);
and I shows empty array. 我显示了空数组。
What's wrong? 怎么了?
--cookie
and -b
are equivalent, they just specify the file to read cookies from. --cookie
和-b
是等效的,它们只是指定要从中读取cookie的文件。 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
. 要保存cookie,必须使用
--cookie-jar
或-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. 如果要使用发送回的cookie更新原始cookie,则可以将相同的文件与两个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. 如您所见,它发送了标题
Cookie: SRV=www3
,它是从文件中读取的。 The resulting cookies_to_del
file contains: 生成的
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
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.
从中读取cookie的文件格式应为纯HTTP标头或Netscape / Mozilla cookie文件格式。
The files I used are Netscape cookie file. 我使用的文件是Netscape cookie文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.