Link to home
Start Free TrialLog in
Avatar of Jamie Youell
Jamie Youell

asked on

CURL sending XML without spaces PHP

$xmlVariable = '<function name="AddFinancial">
              <component name="people">
              <property name="ppl_id"><![CDATA[34234424]]></property>
              </component>
              <component name="bankpayment">
              <property name="tlog_comment"><![CDATA[CURL, order ID: 242344]]>
              </property> <property name="tlog_evtt_id"><![CDATA[bpm]]></property>
              <property name="tlog_debit"><![CDATA[0]]></property>
              <property name="tlog_credit"><![CDATA[2.00]]></property>
              </component>
              </function>';

              $headers = array();
              $headers[] = 'Accept: application/xml';
              $headers[] = 'Content-Type: application/xml';

              $ch = curl_init();
              curl_setopt($ch, CURLOPT_URL, "https://test.testmanager.eu/API/Addfin.asp?api_license=234234");
              curl_setopt($ch, CURLOPT_POST, true);
              curl_setopt($ch, CURLOPT_POSTFIELDS, "input_XML=".$xmlVariable);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
              curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
              curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
              curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0'); 

              $exe  = curl_exec($ch);
              $getInfo = curl_getinfo($ch);

Open in new window


The above CURL sends the XML to the URL but somehow removes all the spaces.

<functionname="AddFinancial"><componentname="people"><propertyname="ppl_id"><![CDATA[8DFB5500-6134-4220-9DB9-6FF841372C26]]></property></component><componentname="bankpayment"><propertyname="tlog_comment"><![CDATA[CURL,orderID:]]></property><propertyname="tlog_evtt_id"><![CDATA[bpm]]></property><propertyname="tlog_debit"><![CDATA[0]]></property><propertyname="tlog_credit"><![CDATA[2.00]]></property></component></function>
<functionname="AddFinancial"> should be <function name="AddFinancial">

Open in new window


 If tried using differt headers but until now nothing works. Any ideas? Thanks in advanced.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

cURL does not remove spaces.  Something else is in play here (possibly a badly-written regular expression).  Please try making the POST request to this URL and post the response you get here, in the code snippet.

https://iconoun.com/demo/request_reflector.php
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jamie Youell
Jamie Youell

ASKER

@julian thanks noted that. @ray Thanks you very much. This was very helpfull and it works perfect. If been looking for a solution for reflecting the POST from Curl. The request reflector does the job!