看起来像是like服务器忽略了我的cookies。(在PHP curl中使用)
获取cookie很好,但返回不起作用。当我用浏览器访问网站并删除cookie时,我得到了完全相同的行为。
我该如何解决这个问题呢?这跟https有什么关系吗?
代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://example.com/createAccount.jsp');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/var/www/ajax/Cache/Sessions/cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "/var/www/ajax/Cache/Sessions/cookie.txt");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$result = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
$data = array('_dyncharset' => 'UTF-8',
'_DARGS' => '/createAccount.jsp',
'firstName' => $firstname,
'login' => $email,
'lastName' => $lastname);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_URL, 'https://example.com/createAccount.jsp?action=createAccount');
curl_setopt($ch, CURLOPT_COOKIEFILE, "/var/www/ajax/Cache/Sessions/cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "/var/www/ajax/Cache/Sessions/cookie.txt");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HEADER, true);
$result = curl_exec($ch);
curl_close($ch);发布于 2014-03-31 22:09:53
确保CURLOPT_COOKIEJAR文件可由服务器进程(执行php脚本)写入。
如果这失败了,您可以简单地重用相同的curl实例,只需删除
curl_close($ch);
$ch = curl_init();发布于 2014-03-31 22:17:07
从你的第一个curl请求中删除下面的行。这对你来说应该是可行的:
curl_setopt($ch, CURLOPT_COOKIEFILE, "/var/www/ajax/Cache/Sessions/cookie.txt");CURLOPT_COOKIEFILE用于将cookie从文件发送到服务器。因此,删除此行将意味着不发送cookie。因此服务器不会注意到之前的任何访问:-)
https://stackoverflow.com/questions/22763369
复制相似问题