所以我正在使用足球联赛 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 不能获取内容呢?
最佳答案
好吧,我把它简化为
<?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/