script

Friday, September 28, 2012

How to post xml using cURL?

$xml_data = '<?xml version="1.0" encoding="UTF-8" ?>
                  <books>
                         <book>
                                     <name>Ansi C</name>
                         </book>
                 </books>

';

$URL = "URL TO POST XML";

$ch = curl_init($URL);
//curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
header("Content-Type: text/xml");
echo $output;
curl_close($ch);

No comments:

Post a Comment