Reputation: 51
Hear I am trying to access NSEIndia.com website URL "https://www1.nseindia.com/live_market/dynaContent/live_watch/stock_watch/niftySmallcap50OnlineStockWatch.json".
this is working fine when I am opening this in browser but it is not working when I try to open this using php file_get_contents
.
Please help me or suggest me what should I try another way so I will receive output of this URL in my code.
$url = "https://www1.nseindia.com/live_market/dynaContent/live_watch/stock_watch/niftySmallcap50OnlineStockWatch.json";
echo file_get_contents( $url );
die;
Thank you very much in advance.
Upvotes: 1
Views: 5946
Reputation: 646
See this answer for more info
Basically the webserver is configured in a way that blocks request from file_get_contents.
Maybe try curl?
In the linked question the following code is provided
// 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);
Upvotes: 2