【问题标题】:Accept cookies using cURL?接受使用 cURL 的 cookie?
【发布时间】:2012-04-25 11:44:40
【问题描述】:

我一直在尝试使用 cURL 获取网页的内容,但无法让 cURL 接受 cookie。 例如,在 Target.com 上,当我 cURL 时,它仍然说我必须启用 cookie。

这是我的代码:

$url = "http://www.target.com/p/Acer-Gateway-15-6-Laptop-PC-NV57H77u-with-320GB-Hard-Drive-4GB-Memory-Black/-/A-13996190#?lnk=sc_qi_detailbutton";
$ch = curl_init();    // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // times out after 4s
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0"); 
$cookie_file = "cookie1.txt";
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
$result = curl_exec($ch); // run the whole process
curl_close($ch); 
echo $result;

我还缺少什么? 顺便说一下,cookie1.txt文件是077权限。

【问题讨论】:

  • 077 是无效权限,这意味着所有者(可能是 apache)没有访问权限。尝试将其设置为 644,因为它只是一个文件。
  • @MikePurcell 你为什么要把它作为评论发布?将其发布为答案。
  • @Truth: 不确定是不是类型。

标签: php cookies curl file-get-contents


【解决方案1】:

077 是格式错误的权限设置,这意味着所有者(可能是 apache)没有访问权限。尝试将其设置为 644(所有者具有读/写权限),因为它只是一个文件。

【讨论】:

  • 嗨,你发现你的问题了吗?
猜你喜欢
  • 2014-12-01
  • 2020-06-14
  • 2022-01-16
  • 2012-11-25
  • 1970-01-01
  • 1970-01-01
  • 2012-04-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多