php - file_get_contents 不返回任何数据

标签 php

所以我正在使用足球联赛 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);

如你所料,这让我经历了整个灾难。 不确定这是否对您有帮助。

关于php - file_get_contents 不返回任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40712122/

相关文章:

php - 在一个查询语句 php 中将 2 个表连接在一起

php - 无法使用 codeigniter php 获取静态下拉值

php - 我应该如何在 MySQL 数据库中存储换行符?

php - Laravel 从 php 输出缓冲区下载文件 VS。私有(private)存储文件夹|安全

php - PHP 和 PSR-8 中的 HuggableInterface

php - Google Dictionary API 的 json_decode

javascript - 类似 Excel 的 PHP 和 AJAX 中没有按钮的表格更新

php - 从列 Mysql 中修剪额外的空间

PHP cURL 无法在 Windows 上的 Apache 中正确加载

php - 我如何在 android spinner 中合并两个 json 对象