I am attempting to pass some post data to a external site providing some verification services for me. I'm using this function to pass the data:
function do_post_request($url, $data, $optional_headers = null) {
$params = array('http' => array(
'method' => 'post',
'content' => $data
));
if ($optional_headers!== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
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 $response;
}
The data I'm passing is just a string of xml.
Everytime I try it with a regular (http) url it works fine, returns me the contents of the page (which is also xml data). However whenever I try to use a secure (https) url it throws this error:
sample source:
<html>
<head>
<title>Submission Test</title>
</head>
<body>
<?php
function do_post_request($url, $data, $optional_headers = null) {
$params = array('http' => array(
'method' => 'post',
'content' => $data
));
if ($optional_headers!== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
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 $response;
}
echo "Let's do a little test.<br><br>";
echo "Data to be submitted:<br><br>";
$xmlsend = new SimpleXMLElement('<dataxinquiry></dataxinquiry>');
/*
build my xml submission here
*/
echo "<xmp>";
echo $xmlsend->asXML();
echo "</xmp><br><br>";
echo "Submitting data.....<br><br>";
$result = do_post_request('https://www.mysecureaddress.com', $xmlsend->asXML());
echo "Returned information:<br><br>";
echo "<xmp>";
echo $result;
echo "</xmp>";
?>
</body>
</html>
anyone know what might be causeing this problem and what I could do about it?