0

I am trying to connect to an API using cURL and https and I don't get it work.

It work perfectly with http but when i change it to https in the $url variable, it takes more than 30 seconds to execute and finally it shows false as a result.

This is the function:

$url = 'https://api.xxxxxxx.com/api.php?user=xxxx&pass=xxxx';

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);

$result = curl_exec($ch);
curl_close($ch);

echo $result;

If I debug with this:

debug(curl_init($url));

I get:

resource

Any idea which could be the cause?

Alvaro
  • 40,778
  • 30
  • 164
  • 336
  • Have a look here? http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/ – Chris Nov 30 '12 at 11:25
  • If you take a look at my code, you will see I am using what he calls " the quick fix" plus I am not getting any warning or error. – Alvaro Nov 30 '12 at 11:28
  • Possible duplicate: http://stackoverflow.com/questions/4372710/php-curl-https – looper Nov 30 '12 at 11:29
  • 1
    Have you tried connecting to another https page? Such as the ebay login page etc – Chris Nov 30 '12 at 11:29
  • @looper Again, I am already using what they all call "the quick fix"... – Alvaro Nov 30 '12 at 11:29
  • @Chris, connecting here, for example `https://api.sandbox.ebay.com/` it seems to work although the return value is empty. You think its a problem of the URL i am trying to connect? I can also connect to `https://google.com` and i get a 301 moved message (as expected I guess). – Alvaro Nov 30 '12 at 11:35
  • At a post here it is suggested to use a different port, I have no idea if it will help. http://stackoverflow.com/a/4017643/1169669 – Chris Nov 30 '12 at 12:04
  • It seems it is because the host I am trying to connect doesn't allow HTTPS connections... – Alvaro Nov 30 '12 at 12:25
  • Ah not so good. Tried it on a local machine? – Chris Nov 30 '12 at 12:30
  • I am executing my code from the local machine yeah. – Alvaro Nov 30 '12 at 12:52
  • Hmm - have you tried something other than curl? – Chris Dec 02 '12 at 10:31
  • Yeah Chris. I would say it is because the host I am trying to connect doesn't support `https` connections. Thanks for your help! – Alvaro Dec 03 '12 at 09:58

1 Answers1

0

It ended up to be that the website was trying to access didn't allow secure connections.

Alvaro
  • 40,778
  • 30
  • 164
  • 336