2013-07-19 161 views
-1

当我在浏览器中键入一个URL时,它会返回详细的输出。但是,当我尝试通过curl请求执行此操作时,请求会返回一个空的空白空间。为什么发生这种情况?curl php空白空间

网址是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); 
} 
+0

我下面是给我一个空白页 – StephenTG

+0

的URL @StephenTG对不起接入码是唯一的好一次,这意味着其他人点击该链接。我现在会给你发一封。 – user2600095

+1

这听起来像它可能是问题... – StephenTG

回答

0

请使用CURLOPT_HEADER检查响应头的任何错误。在下面的格式

+0

所以设置这个curl_setopt($ curl,CURLOPT_HEADER,true); ? – user2600095

+0

我得到这个:HTTP错误411长度要求 – user2600095

0

使用卷曲 -

$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); 
+0

curlopt_useragent有什么意义? – user2600095

+0

当通过cURL请求URL时,服务器会响应该请求,就像通过浏览器发送请求一样。但是,默认的cURL请求不会指定某些服务器验证请求所需的信息,例如。用户代理,语言等 – nks

+0

此代码不起作用。我修改它为我的例子,它返回500px页面,说oops肯定有错误。 – user2600095