Curl Php在浏览器中返回NULL

时间:2015-12-08 02:27:10

标签: php arrays json xml curl

我正在尝试向第三方票务系统进行身份验证,连接并检索座席信息。然后,我想解析检索到的文件,以便只显示特定的信息,如'id'和''active_since',但我在浏览器中收到NULL错误。有什么帮助吗?

由THIRDPARTY返回的文件

[agent] => Array
        (
            [active_since] => 2015-11-30T08:09:26-01:00
            [available] => 1
            [created_at] => 2015-05-14T19:15:18+00:00
            [id] => XXXXX 
            [occasional] => 
            [points] => 5520
            [scoreboard_level_id] => 5000402007
            [signature] => 
            [signature_html] => 

下面是PHP CURL代码。

 <?php
    $username = "xxxxxxx";
    $password = "xxxxxxx";
    $url = 'http://support.xxxx.com/agents/xxx132067';

    $cURL = curl_init();
    curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($cURL, CURLOPT_URL, $url);
    curl_setopt($cURL, CURLOPT_HTTPGET, true);
    curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Accept: application/json',
        'header' => "Authorization: Basic " . base64_encode("$username:$password")      

    )
    );

    $result = file_get_contents($url);
    // Will dump a beauty json :3
    var_dump(json_decode($result, true));

    $array["active_since"];

    ?>

1 个答案:

答案 0 :(得分:0)

s:label key="gettext\('$1'\)" 标题中删除'header' =>。它应该如下:

Authorization

我根本没有看到你在呼唤卷曲。用适当的卷曲呼叫替换你的"Authorization: Basic " . base64_encode("$username:$password")

file_get_contents