Jump to content

https submission problems


jerez_z

Recommended Posts

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:

 

Fatal error: Uncaught exception 'Exception' with message 'Problem with https://www.mysecureaddress.com ' in C:\xampp\htdocs\chris\index.php:18 Stack trace: #0 C:\xampp\htdocs\chris\index.php(71): do_post_request() #1 {main} thrown in C:\xampp\htdocs\chris\index.php on line 18

 

 

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.