我正试图从我的Api中获取,我在php中使用curl登录到一页并且 然后得到另一页从你的第一页传递所有cookie,但我一直拒绝访问!
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");
curl_setopt($ch, CURLOPT_URL,"http://www.supersaas.com/api/users");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "?account=myname&password=mypassword");
ob_start(); // prevent any output
curl_exec ($ch); // execute the curl command
ob_end_clean(); // stop preventing output
curl_close ($ch);
unset($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookieFileName");
curl_setopt($ch, CURLOPT_URL,"http://www.supersaas.com/api/users?id=12");
$buf2 = curl_exec ($ch);
curl_close ($ch);
echo "<PRE>".htmlentities($buf2);
这段代码有什么问题???? 感谢
答案 0 :(得分:0)
您的登录未成功,因此您在文件中包含无效的Cookie并且从服务器中拒绝了第二个curl请求。
从?
删除?account
标记。所以它将是
curl_setopt($ch, CURLOPT_POSTFIELDS, "account=myname&password=mypassword");