Jump to content
Sign in to follow this  
ameliabob

Curl not returning values

Recommended Posts

I am trying to get to a site with the following code:

	        $syms ="T,IBM";
        $closeDict = array();    
        $url = "https://api.iextrading.com/1.0/stock/market/batch?types=quote&filter=symbol,latestPrice,&symbols="+$syms;
           $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    
    
           $jresult = curl_exec($ch);
           $info = curl_getinfo($ch);
        echo(print_r($info));
        echo("alertjresult is ".$jresult);
	

and several things are or are not happening. 

1) the url doesn't get put into the header

2) There is no response Notice the alerts at the end.

I seem to recall reading that there is an option to set when accessing a https site.  However there is no password or other sign in function.  If you cut and paste the url into a browser it operates just fine.

What I have I overlooked??

[code}]

Array ( => http://0/ [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 1.594 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [redirect_url] => [primary_ip] => [certinfo] => Array ( ) [primary_port] => 0 [local_ip] => [local_port] => 0 ) 1alertjresult is alertresult is

[/code]

Share this post


Link to post
Share on other sites

the url doesn't get put into the header

What does that mean?

The first element in the array says http://0/, so your URL is "0".  That's because you're using the plus sign on the line where you define the URL, and the plus sign is for addition.  You use a dot to concatenate strings.

Share this post


Link to post
Share on other sites

OK, My error moving from Javascript to PHP. Fixed that and now get but still nothing back

			 		Array ( [url] => https://api.iextrading.com/1.0/stock/market/batch?types=quote&filter=symbol,latestPrice,&symbols=T,IBM [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 20 [redirect_count] => 0 [total_time] => 0.156 [namelookup_time] => 0.047 [connect_time] => 0.11 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [redirect_url] => [primary_ip] => 35.224.167.123 [certinfo] => Array ( ) [primary_port] => 443 [local_ip] => 10.0.0.167 [local_port] => 53785 ) 1alertjresult is alertresult is	

putting the url  into a browser gives the answer result as
 
{"T":{"quote":{"symbol":"T","latestPrice":32.97}},"IBM":{"quote":{"symbol":"IBM","latestPrice":145.23}}}
Now what is missing??

Share this post


Link to post
Share on other sites

Just to close the loop and in case others are looking for the same solution.

I put in the line "echo 'Curl error: '.curl_error($ch);" and found that the error was SSL

Then since putting the url in the browser didn't ask for any user name and password I added the following line to the curl options

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

The false parameter says something to the effect 'don't care about verifying' and allows it to do its thing.

and it works!!

Thanks for getting me on the right path.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×