当我在浏览器中输入 URL 时,它会返回详细的输出。但是,当我尝试通过 curl 请求执行此操作时,请求为空。为什么会这样?
我的代码是:
<!DOCTYPE html>
<?php
function fetchData($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_URL, $url);
$returned = curl_exec($ch);
echo 'Errors: ' . curl_errno($ch) . ' ' . curl_error($ch) . '<br><br>';
curl_close ($ch);
echo $returned;
return $returned;
}
);
// Pulls and parses data.
$returned = fetchData("https://api.500px.com/v1/users?oauth_token=xElRwQ6cqItG8Siy9kFBpwkj5sCdlp33NRva5TZU&oauth_verifier=hbNdYnqm8BSyuiZYa4KZ&consumer_key=0OvWThqr5j1ZYX1cPaa8y0y1aOfJBbDtpX85fJ42");
var_dump($returned);
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
echo 'Operation completed without any errors';
}
$result = json_decode($returned);
print_r($returned);
// if(!curl_errno($ch))
// {
// $info = curl_getinfo($ch);
// echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
// }
echo "working";
echo curl_error($ch);
echo "workign4";
print_r(curl_getinfo($ch));
echo "working6";
?>
</html>