繁体   English   中英

CURL给出500内部服务器错误

[英]CURL gives 500 Internal server error

我无法使用CURL进行API调用。 以下是使用CURL进行API调用的代码

$ch=curl_init("http://sms.geekapplications.com/api/balance.php?authkey=2011AQTvWQjrcB56d9b03d&type=4");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("Authorization: Bearer"));

// execute the api call
$result = curl_exec($ch);
echo ($result);

首先,您可能想为此使用一个函数..并且您的CURL无法正确构建。 请看我的例子

//gets geekapplications SMS balance
function getBalance() {
    $url = 'http://sms.geekapplications.com/api/balance.php?' . http_build_query([
            'authkey' => '2011AQTvWQjrcB56d9b03d',
            'type' => '4'
        ]);
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    $http = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    if ($http == 200) {
        $json = @json_decode($response, TRUE);
        return $json;
    } else {
        echo 'There was a problem fetching your balance...';
    }
}

在您的控制器中使用它try print_r($this->getBalance()); 应该用您的余额输出一个数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM