curl php empty blank space



当我在浏览器中键入URL时,它会返回详细的输出。然而,当我尝试通过curl请求来实现这一点时,该请求返回一个空空格。为什么会发生这种情况?

URL为https://api.500px.com/v1/users?oauth_token=AihBz6ZWedu3VxnQdy2tqWtbwV86wtOuXumhPapk&oauth_ verifier=YhKo0kaGhfw0dFhparxU&consumer_key=0OvWThqr5j1ZYX1cPaa8y0y1aOfJBbDtpX85fJ42

我的代码是:

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

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

使用以下格式的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);

最新更新