We help IT Professionals succeed at work.

CURL sending XML without spaces PHP

Jamie Youell
Jamie Youell asked
on
669 Views
Last Modified: 2017-04-12
$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.
Comment
Watch Question

Most Valuable Expert 2011
Author of the Year 2014

Commented:
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
Most Valuable Expert 2011
Author of the Year 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Most Valuable Expert 2011
Author of the Year 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
@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!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.