I am trying duplicate the functionality of this command:
exec('curl -k -d "pameters=here" https://apiurlhere.com', $output);
with curl_exec():
$url = 'https://apiurlhere.com?parameters=here';
$ci = curl_init();
curl_setopt($ci, CURLOPT_POST, TRUE);
curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ci, CURLOPT_URL, $url);
$response = curl_exec($ci);
curl_close ($ci);
print_r($response);
I have been trying the different options found in the docs (http://php.net/manual/en/function.curl-setopt.php), and thought it was CURLOPT_SSL_VERIFYPEER, but it still failed (response comes back empty).
The URL i’m posting to uses SNI which is causing cURL to fail when the SSL cert returns a different host name than it’s expecting.
Is there a curl_setopt equivalent to -k?
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE)is the equivalent of-kon the command line (which you shouldn’t really use, since it makes the connection vulnerable to MITM attacks).Your problem here is that you’re assuming that
-d "pameters=here"is equivalent to putting these parameters in the URL query like thishttps://apiurlhere.com?parameters=here.This isn’t the case, see documentation for
-d:You should probably use
POSTFIELDSfor this: