2017-02-16 64 views
0

我收到一个错误,不知道这是否为头错误?饲料工程100%,当我使用邮差用相同的标题和URL用CURL发送标题并接收Json数据 - PHP

{"error":{"message":"The content version specified in the request is not supported.","code":101}} 

这里是我想,我的PHP代码

$url = 'http://x.x.x.x/api/slot/0/io/'; 
$headers = array(
     'Accept:vdn.v1', 
     'Content-Type:application/json' 

    ); 

$ch = curl_init(); 

    // Now set some options (most are optional) 

    // Set URL to download 
    curl_setopt($ch, CURLOPT_URL, $url); 

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

    // Set a referer 
    curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm"); 

    // User agent 
    curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0"); 

    // Include header in result? (0 = yes, 1 = no) 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    $headers 

    // Should cURL return or print out the data? (true = return, false = print) 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

    // Timeout in seconds 
    curl_setopt($ch, CURLOPT_TIMEOUT, 10); 

    // Download the given URL, and return output 
    $output = curl_exec($ch); 

    // Close the cURL resource, and free system resources 
    curl_close($ch); 

print_r($output);exit; 
+0

错误表明您的Accept头存在问题。检查字符串“Accept:vdn.v1”中是否有任何拼写错误。 – jorgonor

+0

@jorgonor我再次检查邮差和我的PHP代码接受:vdn.v1是正确的 – user580950

+1

如果它在邮差工程中,单击右上角的'代码'链接,在“生成代码段”弹出式选择“PHP曲线”。生成的代码可以很容易粘贴到脚本中,并生成相同的http请求。 –

回答

0

我从

$headers = array(
     'Accept:vdn.v1', 
     'Content-Type:application/json' 

    ); 
改变了头

TO

$headers = array(
     'Accept:vdn.v1' 

    ); 

tha t排序了所有问题