我对cURL的cookies有问题。
在出现问题后,我打开了verbose函数,发现即使服务器发送的是正日期,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将expires设置为负值。
有人有主意了吗?
编辑:
下面是我使用的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);来自cookie jar的数据:
#HttpOnly_.test.com TRUE / FALSE -1630016318 _test_sess "test"发布于 2012-03-21 08:09:48
你的代码对我来说工作得很好。您的示例站点http://www.site.com/甚至不会尝试设置任何cookie。当我在设置cookies的站点(即FaceBook)上运行它时,我得到了积极的过期时间。
该错误可能是服务器在尝试设置cookies时设置了不正确的值而导致的问题。
任何负数都会立即使
过期(cite)。
我最好的猜测是,该网站正试图使您的cookie过期。
发布于 2012-04-12 19:25:26
也许这是与Curl doesn't recognize expires value in cookie correctly相同的问题-“您的计算机上遇到了一个问题,因为32位有符号整数值的限制。”
https://stackoverflow.com/questions/9772673
复制相似问题