Question

I’m trying to use CakePHP’s HttpSocket to connect to Foursquare’s API, particularly the venue search endpoint (https://developer.foursquare.com/docs/venues/explore). As you can see, Foursquare’s API is accessed over HTTPS, so I added the following in my controller:

$httpSocket = new HttpSocket();
$results = $httpSocket->get('https://api.foursquare.com/v2/venues/search', array(
    'query' => $query
));

However, this throws the following error:

stream_socket_client(): Peer certificate CN='*.a.ssl.fastly.net' did not match expected CN='api.foursquare.com' stream_socket_client(): Failed to enable crypto stream_socket_client(): unable to connect to ssl://api.foursquare.com:443 (Unknown error)

How do I connect to secure URLs (and particularly Foursquare’s) using CakePHP’s HttpSocket?

Was it helpful?

Solution

The response indicates that the SSL certificate foursquare have is for another domain (their CDN), you either need to connect directly to the API using the CDN domain, or ignore the fact the certificates are for the wrong host.

The section on handling SSL certificates explains how to ignore incorrect hosts: http://book.cakephp.org/2.0/en/core-utility-libraries/httpsocket.html#handling-ssl-certificates (ssl_verify_host)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top