vendredi 3 novembre 2017

API integration using PHP curl

I am writing a script that does foreign exchange using an API to do it in realtime.

I presume that the problem is in my implementation of curl, as I get no output from this :

        $currencyBase    = "USD";
        $currencyForeign = "EUR";
        $url             = 'http://ift.tt/2zbYTH6' . $currencyBase . '&to_currency=' . $currencyForeign . '&apikey=KCUGBA9AP3Z1E2P8';

        echo $currencyBase;

        // create curl resource
        $c = curl_init($url); //Initialize a cURL session
        curl_setopt($c, CURLOPT_HEADER, 0);  //Set an option for a cURL transfer
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); //Set an option for a cURL transfer                           
        $this->fxRate = doubleval(curl_exec($c));  
        curl_close($c);  //Close a cURL session

I have hardcoded

        $currencyBase    = "USD";
        $currencyForeign = "EUR";

for debugging and I have also tried print_r($c) to see if I'm passing anything but I still get no output.

I know that my API call works because I have tried the link with entered USD and EUR and I get a response when I enter it in the browser as follows:

http://ift.tt/2h9vuXf

But I always get an empty response when I print the output.




Aucun commentaire:

Enregistrer un commentaire