<?php
$server ="http://yourservername/getservicexml.php";
$xmldata ="<tests>
<control>
<module>Modulename</module>
</control>
<test>
<sn>5555</sn>
<ticket>555</ticket>
<test_station>5555</test_station>
<tester_name>testername</tester_name>
<user>user</user>
<result>F</result>
<resource_name>resourcename</resource_name>
<test_log>
<![CDATA[
Log message or your data text data field
]]>
</test_log>
</test>
</tests>
";
function sendRequest($requestXML,$server)
{
// $server = 'http://127.0.0.1/exam/php_xml/receive_postxml.php';
$headers = array(
"Content-type: text/xml",
"Content-length: ".strlen($requestXML),
"Connection: close"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $server);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 200);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXML);
// curl_setopt($ch, CURLOPT_POSTFIELDS, "?XML=TT&password=".$password."&etc=etc");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
echo $data;
if(curl_errno($ch)){
$errmes = curl_error($ch);
$textlog = date("d/M/Y H:i:s",time())." ".$errmes." something went wrong..... try later\n";
//saveaction(ODCSENDLOG,$textlog);
echo $textlog;
exit();
}else{
curl_close($ch);
}
if(!$data)
{
return false;
}
return $data;
}
sendRequest($xmldata,$server);
?>
/*------------------------------------------*/
// Received data getservicexml.php
<?php
if (!function_exists('getallheaders'))
{
function getallheaders()
{
$headers = '';
foreach ($_SERVER as $name => $value)
{
if (substr($name, 0, 5) == 'HTTP_')
{
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
}
$arr1 = getallheaders(); //apache_response_headers();
$txt = "";
foreach($arr1 as $key => $value)
{
$txt .= $key.":".$value."\n";
}
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])){
$xml = $GLOBALS["HTTP_RAW_POST_DATA"];
echo $xml;
}
$txt .= $xml;
$handle=fopen("testxmlheader.log","a+");
fwrite($handle,$txt."\n");
fclose($handle);
function xmlhead_savelog($text)
{
$xmlstr="<?xml version=\"1.0\" ?>";
$xmlstr.="<tests>";
$xmlstr.="<control>";
$xmlstr.="<module>SAVELOGFILE</module>";
$xmlstr.="</control>";
$xmlstr.=$text;
$xmlstr.="</tests>";
return $xmlstr;
}
?>