During integration projects or during such similar situations you may have across a necessity to transfer XML data or plain text file across server locations.
Curl comes in handy during such scenarios. Following program is used to post XML data using Curl. In order for Curl to function, ensure that PHP settings has the curl module installed and that the libraries/dll libeay32, ssleay32 is installed in your server.
<?php /* File name: postdata.php */ $post_url = "http://localhost/demo/postdata2.php"; $xml_string = '<?xml version="1.0" encoding="UTF-8"?> <books> <book isbn="978-1594489587"> <title>The Brief Wondrous Life of Oscar Wao</title> <publisher>Riverhead Hardcover </publisher> <amazon_price>14.97 </amazon_price> <author_firstname>Junot </author_firstname> <author_lastname>Diaz </author_lastname> </book> <book isbn="999-1594489501"> <title>A Thousand Splendid Suns </title> <publisher>Riverhead Hardcover </publisher> <amazon_price>14.27 </amazon_price> <author_firstname>Khaled </author_firstname> <author_lastname>Hosseini </author_lastname> </book> </books>'; $ch = curl_init($post_url); curl_setopt ($ch, CURLOPT_POST, true); curl_setopt ($ch, CURLOPT_POSTFIELDS, "xmldata=".$xml_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_VERBOSE, 1); $data = curl_exec($ch); // to get information on the curl resultset $info = curl_getinfo($ch); if(curl_errno($ch)){ print curl_error($ch); } curl_close($ch); ?>