blinks Posted December 4, 2009 Share Posted December 4, 2009 Using the following code on my localhost, I can successfully send an XML file to a specific remote server, and have a response returned. However, the same code moved up to a development server (with appropriate changes to $filename from localhost to dev.domain.etc), yields no response. If I rejig the code so that it reads from an XML file on my localhost rather than a POSTed XML, all works fine on DEV. Here's the code - <?php // based on example at http://en.allexperts.com/q/PHP5-3508/2008/12/Regarding-Sending-XML.htm $data = file_get_contents("xmlexampledev.xml"); $arr= array('xmlparam' => $data); $array= http_build_query($arr); $context_options = array ( 'http' => array ( 'method' => 'POST', 'header'=> "Content-type: application/x-www-form-urlencoded " . "Content-Length: " . strlen($array) . " ", 'content' => $array ) ); $filename = "http://dev.domain.com/pid/getpids.php"; //$filename = "http://localhost/pid/getpids.php"; // works $context = stream_context_create($context_options); $response = file_get_contents($filename, false, $context); print_r($response); ?> Here's the bit of code that grabs the XML POST - $xmlstr = $_POST['xmlparam']; //if testing via direct file load, use below instead of $_POST above to load xml file as string //$xmlstr = file_get_contents(XML_SOURCE_FILENAME); //convert $xmlstring into SimpleXMLElement $xml = new SimpleXMLElement($xmlstr); TIA Link to comment https://forums.phpfreaks.com/topic/183935-sending-xml-file-through-post-ok-on-localhost-but-not-dev/ Share on other sites More sharing options...
blinks Posted December 8, 2009 Author Share Posted December 8, 2009 Solved the problem. The calling code is now - <?php //http://www.usenet-forums.com/php-language/21143-need-post-xml-file-url.html $xmlfile = file_get_contents("xmlexampledev.xml"); $alternate_opts = array( 'http'=>array( 'method'=>"POST", 'header'=>"Content-type: application/x-www-form-urlencoded\r\n" . "Content-length: " . strlen("$xmlfile"), 'content'=>"$xmlfile" ) ); $context = stream_context_create($alternate_opts); $fp = fopen('http://www.domain.com/pid/getpids.php', 'r', false, $context); fpassthru($fp); fclose($fp); ?> and the bit that grabs the POST is - $xmlstr = file_get_contents("php://input"); Link to comment https://forums.phpfreaks.com/topic/183935-sending-xml-file-through-post-ok-on-localhost-but-not-dev/#findComment-973218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.