jerez_z Posted March 7, 2008 Share Posted March 7, 2008 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 https://forums.phpfreaks.com/topic/94834-https-submission-problems/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.