I am trying to send a post request to a URL with HTTPS and I keep getting an error.
This is my code:
function do_post_request($data, $optional_headers = null) {
$params = array('http' => array(
'method' => 'POST',
'content' => http_build_query($data)
));
$url = 'https://url';
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
fpassthru($fp);
if (!$fp) {<--- falls here
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return array(substr(trim(strip_tags($response)),0,3), trim(strip_tags($response)));
}
The error i get is:
Fatal error: Uncaught exception 'Exception' with message 'Problem with https://gateWay.pelecard.biz/PayProcess/English, ' in C:\PelecardProjects\aspsite\Post\PHP\PayEng.php:103 Stack trace: #0 C:\PelecardProjects\aspsite\Post\PHP\PayEng.php(83): do_post_request(Array) #1 {main}
I read somewhere that I need to enable php OpenSSL extension maybe?