首页 > 解决方案 > 在 PHP 中调用 API GET 请求后没有响应

问题描述

好的,所以我一直在开发这个从 API 获取数据的应用程序,我一直在用 PHP 对其进行编码,但我最近遇到了一个错误。我没有得到任何回应

我从在线博客获得了脚本,因为我以前没有使用 cURL 的经验

curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
       'Authorization: xxxx',
       'Content-Type: application/json',
    ));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

    // EXECUTE:
    $result = curl_exec($curl);
    if(!$result){die("Connection Failure");}
    curl_close($curl);
    return $result;

    $get_data = callAPI('GET', 'https://api.brawlapi.cf/v1/player?tag=Y2QPGG', false);
    $response = json_decode($get_data, true);
    $errors = $response['response']['errors'];
    $data = $response['response']['data'][0];

我使用的 API 是https://docs.brawlapi.cf/#/endpoints/player

标签: phpapihttpcurlget

解决方案


推荐阅读