0

当我在浏览器中输入 URL 时,它会返回详细的输出。但是,当我尝试通过 curl 请求执行此操作时,该请求会返回一个空白区域。为什么会这样?

网址是https://api.500px.com/v1/users?oauth_token=AihBz6ZWedu3VxnQdy2tqWtbwV86wtOuXumhPapk&oauth_verifier=YhKo0kaGhfw0dFhparxU&consumer_key=0OvWThqr5j1ZYX1cPaa8y0y1aOfJBbDtpX85fJ2

我的代码是:

<!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);
}
4

2 回答 2

0

按以下格式使用 curl -

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,'client='.$number.'&order='.$orderId);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
$data =curl_exec($ch);
于 2013-07-19T16:11:14.697 回答
0

请使用 CURLOPT_HEADER 检查响应标头是否有任何错误。

于 2013-07-19T15:59:22.953 回答