我正在尝试创建使用IEXtrading API获取股票信息的PHP代码。该API接受对HTTPS URL的GET请求并返回库存数据。我已经整理了一个简单的PHP cURL请求,如下所示,试图获得GOOGL股票的价格:
$url = "https://api.iextrading.com/1.0/stock/googl/price";
$ch = curl_init();
$user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$result = curl_exec ($ch);
echo $result;
//$error = curl_error($ch);
//echo "<hr><br>$error";
curl_close ($ch);
出于某种原因,我得到的回应是网站维护页面,其中包含以下内容:
We’ll be back soon!
Sorry for the inconvenience but we’re performing some maintenance at the moment. Check Twitter for up to date information. If you need to you can always email us or call us at 646.343.2000, otherwise we’ll be back online shortly!
— The IEX Team
似乎我做错了,因为我可以手动转到该网址(https://api.iextrading.com/1.0/stock/googl/price)并返回正确的价格信息。我很欣赏我可能做错的任何见解。
谢谢!