當我在瀏覽器中輸入URL時,會返回詳細輸出。但是,當我嘗試通過捲曲請求來做到這一點時,請求是空的。爲什麼發生這種情況?顯示與瀏覽器請求不同內容的捲曲請求
我的代碼是:
<!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>
我應該添加網址作品一次。如果有人輸入,則需要生成新的密鑰代碼。 – user1605871
你能發佈你正在接收的確切錯誤嗎? –
@YogeshSuthar我沒有收到錯誤。完成curl後,請求返回一個空白區域。手動完成後,它不會返回錯誤。它返回一組關於用戶的信息。 – user1605871