加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – file_get_contents没有返回任何数据

发布时间:2020-12-13 16:06:10 所属栏目:PHP教程 来源:网络整理
导读:所以我正在使用足球联赛API,我让它返回我需要的数据.然而,它现在突然停止工作,我不知道为什么. class leagueTable { public $data; public $baseUri; public $config; public $tr; public function __construct($payload) { $this-data = $payload; $this-co
所以我正在使用足球联赛API,我让它返回我需要的数据.然而,它现在突然停止工作,我不知道为什么.

class leagueTable {
    public $data;
    public $baseUri;
    public $config;
    public $tr;

    public function __construct($payload) {
      $this->data = $payload;
      $this->config = parse_ini_file('config.ini',true);
      $this->baseUri = $this->config['baseUri'];
      $this->writeTable();
    }

    public function writeTable() {
      $resource = 'soccerseasons/' . $this->data . '/leagueTable';
      $response = file_get_contents($this->baseUri . $resource,false,stream_context_create($this->reqPrefs));

      if ($response == "")  {
        echo "Unable to retrieve data,please contact the administrator!<br />
            <a target='_blank' href='".$this->baseUri.$resource."'>JSON</a>";
      }
      $result = json_decode($response);

如果我回应$this-> baseUri. $resource我得到一个工作link所以为什么file_get_contents不能获取内容?

See the page here too.

解决方法

好吧,我愚蠢到这一点

<?php
$response = file_get_contents('http://api.football-data.org/v1/soccerseasons/426/leagueTable');
$result   = json_decode($response);
var_dump($result);

这让我得到了你所期待的整个灾难.不确定这对你有什么帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读