I am trying to execute a url using Curl and i am getting empty output.
However, if we copy-paste Same url in Browser, we are getting value
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20%28%22YHOO%22,%22AAPL%22,%22GOOG%22,%22MSFT%22%29&env=http://datatables.org/alltables.env&format=json
However, when i try same to get value in php using Curl, i am getting Null
php code
<?php
$BASE_URL = "http://query.yahooapis.com/v1/public/yql";
// Form YQL query and build URI to YQL Web service
$yql_query = 'select * from yahoo.finance.quotes where symbol in ("YHOO","AAPL","GOOG","MSFT")&env=http://datatables.org/alltables.env';
$yql_query_url = $BASE_URL . "?q=" .$yql_query. "&format=json";
// Make call with cURL
$session = curl_init($yql_query_url);
curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
$json = curl_exec($session);
echo "<pre>";
print_r($json);exit;
?>
Any suggestion ??????
Following code is working for me
<?php
$BASE_URL = "http://query.yahooapis.com/v1/public/yql";
$query = 'select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20%28"YHOO","AAPL","GOOG","MSFT"%29&env=http://datatables.org/alltables.env&format=json';
echo $yql_query_url = $BASE_URL . "?q=" .$query;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$yql_query_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec ($ch);
curl_close ($ch);
print_r($content);
?>
Query must be properly encoded .
Check it