【发布时间】:2012-03-19 15:11:19
【问题描述】:
我在使用 cURL 的 cookie 时遇到问题。
出现问题后,我打开了详细功能并发现 cURL 将它们设置为负过期日期,即使服务器发送正日期也是如此。
例子:
* Added cookie _c_sess=""test"" for domain test.com, path /, expire -1630024962
< Set-Cookie: _c_sess="test"; Domain=test.com; HttpOnly; expires=Mon, 26-Mar-2012 14:52:47 GMT; Max-Age=1332773567; Path=/
你可以看到 expires 和 max-age 都是正的,但是 cURL 集的过期是负值。
有人有想法吗?
编辑:
这是我使用的 php 代码。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://site.com/");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0');
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiepath);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiepath);
curl_setopt($ch, CURLOPT_HEADER ,1);
curl_setopt($ch, CURLOPT_VERBOSE ,1);
curl_setopt($ch, CURLOPT_STDERR ,$f);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$data = curl_exec($ch);
饼干罐中的数据:
#HttpOnly_.test.com TRUE / FALSE -1630016318 _test_sess "test"
【问题讨论】:
-
显示执行此操作的代码,尤其是生成负时间戳的代码。
-
请添加您用来添加该 cookie 的代码。
-
好的,我从 cookie jar 中添加了数据