XML : Insert PHP variables into CURL XML post

i'm a bit stuck here and would be really thankful if someone could point me in the right direction :)

i'm posting "unauth" value from a form and retrieving it fine. What i'd like to do is to insert it into the XML that i'm posting as a variable. The variable would need to be inserted in the macAddress field. Here's what I have in mind

macAddress="$unauth" (Line 8)

  <?php     session_start();  $unauth = $_POST['unauth'];  $xml_data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>  <TipsApiRequest xmlns="http://www.avendasys.com/tipsapiDefs/1.0">  <TipsHeader version="3.0"/>  <Endpoints>  <Endpoint status="Known" macAddress="$unauth">  <EndpointTags tagName="unauthorized" tagValue="true"/>  </Endpoint>  </Endpoints>  </TipsApiRequest>';  $c = curl_init();  curl_setopt($c, CURLOPT_URL, "https://x.x.x.x/tipsapi/config/write/Endpoint");  curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_ANY);  curl_setopt($c, CURLOPT_USERPWD, 'username:password');  curl_setopt($c, CURLOPT_POSTFIELDS, "$xml_data");  curl_setopt($c, CURLOPT_POST, 1);  curl_setopt($c, CURLOPT_RETURNTRANSFER, true);  curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);  curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false);  curl_setopt($c, CURLOPT_HEADER, false);    $output2 = curl_exec($c);    if($output2 === false)  {  trigger_error('Erreur curl : '.curl_error($c),E_USER_WARNING);  }  else  {`enter code here`  var_dump($output2);  var_dump($_POST);  }  curl_close($c);  ?>    

Here's the XML response I get

  '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><TipsApiResponse xmlns="http://www.avendasys.com/tipsapiDefs/1.0"><TipsHeader exportTime="Mon Jan 25 20:10:18 GMT 2016" version="6.5"/><StatusCode>Success</StatusCode><TipsApiError><ErrorCode>InvalidXml</ErrorCode><Message>Endpoint MAC Address "&amp;#x24;unauth" is invalid</Message></TipsApiError></TipsApiResponse>    

Thanks a lot !

No comments:

Post a Comment