使用curl对bitbucket-api进行GET请求

时间:2013-02-21 20:02:59

标签: php bitbucket-api

我正在尝试做一个简单的GET请求并返回屏幕上的响应。当我加载页面时,我得到一个空白页面。我觉得我很接近,但我不确定我哪里出错了。

我假设如果它成功运作我应该得到某种回应。

    $url='https://api.bitbucket.org/1.0/user/';

    $curl = curl_init();

    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ); 
    curl_setopt($curl, CURLOPT_USERPWD, "username:password");
    curl_setopt($curl, CURLOPT_HEADER, true); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_URL, $url);

    curl_exec($curl);

1 个答案:

答案 0 :(得分:3)

要不返回空白页,您需要编写

echo curl_exec($curl);

或 删除这一行:

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);