API via curl

I used to be able to do this:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://online-go.com/api/v1/players/");
curl_setopt($ch, CURLOPT_HEADER, FALSE);
$response = curl_exec($ch);

It works with the mockup API but I get an empty array with the actual API.
string(0) “”

Direct access to this url with the browser works fine.

Hi @pounamu

You need to make sure you are pointing at the https version of the site… the http version will probably issue a 302 that you aren’t handling there.

Whether I use https or not, $response is always bool(false) with the exact same code as above.
Curl is enabled on the server.

I tried a local easyphp server and a remote dedicated server with the same result.

Your code works for me with the HTTPS URL. Did you try running Curl on the command line?

I tried by hand on the command line. It works:

curl --include "https://online-go.com/api/v1/players/"

(on Windows I had to change single quotes to double quotes)

I managed to get an error out of curl:

Fatal error: Curl failed with error #60: SSL certificate problem: self signed certificate in certificate chain

I solved the problem by:

1- downloading http://curl.haxx.se/ca/cacert.pem

2- adding the option
curl_setopt($ch, CURLOPT_CAINFO, "C:\...\cacert.pem");

1 Like