我想使用MTA API(大都会运输管理局)服务。但是当我发送请求时,它将返回一个文件。如何从MTA API获取数据?
http://datamine.mta.info/mta_esi.php?key=MYAPIKEY&feed_id=26
答案 0 :(得分:1)
使用laravel
,
composer
安装guzzlehttp个包
composer require guzzlehttp/guzzle
在控制器中使用它的命名空间:
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
然后你就可以了,
$client = new Client();
$api_response = $client->get('http://datamine.mta.info/mta_esi.php?key=MYAPIKEY&feed_id=26');
$response = json_decode($api_response);
// do your stuff with the response