听说我想访问NSEIndia.com网站的网址"https:/www1.nseindia.comlive_marketdynaContentlive_watchstock_watchniftySmallcap50OnlineStockWatch.json。".
当我在浏览器中打开这个时,它工作得很好,但当我试图用php打开这个时,它就不能工作了。file_get_contents
.
请帮助我或建议我应该尝试另一种方式,使我将收到这个URL的输出在我的代码。
$url = "https://www1.nseindia.com/live_market/dynaContent/live_watch/stock_watch/niftySmallcap50OnlineStockWatch.json";
echo file_get_contents( $url );
die;
非常感谢你提前。
查看 这个 详询
基本上,webserver的配置是阻止file_get_contents的请求。
也许可以试试curl?
在链接的问题中,提供了以下代码
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "example.com");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);