我在使用cURL时遇到问题。
出现问题后,我打开了详细功能,并发现即使服务器发送正日期,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);
来自cookie jar的数据:
#HttpOnly_.test.com TRUE / FALSE -1630016318 _test_sess "test"
答案 0 :(得分:0)
您的代码适用于我。您的示例网站 http://www.site.com/ 甚至不会尝试设置任何Cookie。当我针对设置cookie的网站(即FaceBook)运行它时,我得到了正的到期时间。
错误可能是尝试设置设置错误值的Cookie的服务器上的问题。
任何负数都会立即使Cookie失效(cite)。
我最好的猜测是,该网站正试图让您的Cookie过期。
答案 1 :(得分:0)
可能与Curl doesn't recognize expires value in cookie correctly的问题相同 - “由于32位有符号整数值的限制,您在计算机上遇到了问题。”