Error "empty XML request" as POST request via curl (PHP)



I have created xml request and recieve error message as respond from service: Empty XML request. Service works well as I have configured other system at it. And I don't see any different beside first system uses "wp_remote_post" instead of curl.


My code is:



<?php

$x1=360;
$x2="990";

$data = array(
'xml' => array(
'new_order' => array(
'x1' => $x1,
'x2' => $x2
)
)
);


//create XML
$doc = new DOMDocument('1.0','utf-8');
$doc->formatOutput = true;

foreach($data['xml'] as $key1 => $value1)
{
$node1 = $doc->createElement($key1);
$doc->appendChild($node1);
foreach($value1 as $key2 => $value2)
{
$node2 = $doc->createElement($key2, $value2);
$node1->appendChild($node2);
}
}

$data['xml']= $doc->saveXML();


//***END XML

//SEND XML



$url = "--HTTPS ADDRESS IS CORRECT--";

$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\""
);

$xmlRequest = $data['xml'];


try{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);

// send xml request to a server

curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$connect = curl_exec($ch);

//convert the XML result into array
if($connect === false){
$error = curl_error($ch);
echo $error;
die('error occured');
}else{

$connect = json_decode(json_encode(simplexml_load_string($connect)), true);
}
curl_close($ch);

}catch(Exception $e){
echo 'Message: ' .$e->getMessage();die("Error");
}



//***END SEND XML


?>

No comments:

Post a Comment