【发布时间】:2016-11-21 12:10:11
【问题描述】:
所以我使用了一个足球联赛 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 不能获取内容?
【问题讨论】:
-
stream_context 的用途是什么?在您的示例代码中,
$this->reqPrefs为空,因此它似乎是多余的。还要检查ini_get('allow_url_fopen')的值是否为1。
标签: php