Tuesday, November 4, 2014

Access SSL Enabled URL via Curl

Sometimes you may have problems accessing URL that are SSL enabled. The solution is to simply set the flags below:


    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
To output and debug the problem you can:
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_STDERR, fopen('php://temp', 'rw+'));
$result = curl_exec($ch);
curl_close($ch);

if ($result === FALSE) {
    printf("cUrl error (#%d): %s
\n", curl_errno($curlHandle),
           htmlspecialchars(curl_error($curlHandle)));
}

rewind($verbose);
$verboseLog = stream_get_contents($verbose);

print_r($verboseLog);