使用以下php代码
$url = "http://ichart.finance.yahoo.com/table.csv?s=EURUSD%3DX&a=6&b=27&c=2011&d=7&e=05&f=2011&g=d&ignore=.csv";
$this->trace("Geting from: $url");
$raw_quote_data = file_get_contents($url);
yahoo.com返回404错误,但url是正确的,在我的互联网浏览器下工作。
我也尝试用stream_context_create设置用户代理的标头,但不工作。
也许是我的主机问题(000webhost)和雅虎阻止它?
使用Curl函数。
<?php
$url = "http://ichart.finance.yahoo.com/table.csv?s=EURUSD%3DX&a=6&b=27&c=2011&d=7&e=05&f=2011&g=d&ignore=.csv";
$process = curl_init($url);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_RETURNTRANSFER,1);
curl_setopt($process,CURLOPT_CONNECTTIMEOUT,1);
$response = curl_exec($process);
curl_close($process);
echo $response;
?>
输出i got:
Date,Open,High,Low,Close,Volume,Adj Close 2011-08-04,1.43,1.43,1.43,1.43,000,1.43 2011-08-03,1.43,1.43,1.43,1.43,000,1.43 2011-08-02,1.42,1.42,1.42,1.42,000,1.42 2011-08-01,1.44,1.44,1.44,1.44,000,1.44 2011-07-29,1.42,1.42,1.42,1.42,000,1.42 2011-07-28,1.43,1.43,1.43,1.43,000,1.43 2011-07-27,1.45,1.45,1.45,1.45,000,1.45