php cURL - post and echo result: "Error in structure xml or wrong encoded decoded..."
<p>I try to post and get result by cURL, with no success yet...</p>

<p>Description-manual of information privider says: "In odder to send request to server you must send POST request with variable xml encoded in base64. Xml variable consist of XML special format. Examle PHP:</p>

<pre><code>   $curl = curl_init();
   curl_setopt($curl, CURLOPT_URL, 'http://test.client-shop-logistics.ru/index.php?route=deliveries/api');
   curl_setopt($curl, CURLOPT_POST, 1);
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($curl, CURLOPT_POSTFIELDS, 'xml='.urlencode(base64_encode($xml)));
   curl_setopt($curl, CURLOPT_USERAGENT, 'Opera 10.00');
   $res = curl_exec($curl);
   curl_close($curl);
</code></pre>

<p>Request example:</p>

<pre><code>&lt;request&gt;
  &lt;function&gt;get_order_status_array&lt;/function&gt;
  &lt;api_id&gt;API_ID&lt;/api_id&gt;
  &lt;deliveries&gt;
    &lt;code&gt;135834675500056751&lt;/code&gt;
    &lt;code&gt;135834675500056750&lt;/code&gt;
    &lt;code&gt;135833991800056758&lt;/code&gt;
  &lt;/deliveries&gt;
&lt;/request&gt;
</code></pre>

<p>Answer example:</p>

<pre><code>&lt;answer&gt;
  &lt;error&gt;0&lt;/error&gt;
  &lt;deliveries&gt;
    &lt;delivery&gt;
      &lt;code&gt;135834675500056750&lt;/code&gt;
      &lt;order_id&gt;400004&lt;/order_id&gt;
      &lt;status&gt;New&lt;/status&gt;
      &lt;payment_status/&gt; 
      &lt;vozvrat_status/&gt; 
      &lt;errors/&gt;
      &lt;pickup_id/&gt;
      &lt;oplacheno_poluchatelem&gt;0&lt;/oplacheno_poluchatelem&gt;
      &lt;products&gt;
        &lt;product&gt;
          &lt;articul&gt;4556-56&lt;/articul&gt;
          &lt;name&gt;test name&lt;/name&gt;
          &lt;quantity&gt;10&lt;/quantity&gt;
          &lt;price&gt;1000&lt;/price&gt;
          &lt;number_of_return&gt;0&lt;/number_of_return&gt;
          &lt;number_of_delivered&gt;0&lt;/number_of_delivered&gt;
          &lt;status/&gt;
        &lt;/product&gt;
        &lt;product&gt;
          &lt;articul&gt;22229&lt;/articul&gt;
          &lt;name&gt;Test product&lt;/name&gt;
          &lt;quantity&gt;20&lt;/quantity&gt;
          &lt;price&gt;2000&lt;/price&gt;
          &lt;number_of_return&gt;0&lt;/number_of_return&gt;
          &lt;number_of_delivered&gt;0&lt;/number_of_delivered&gt;
          &lt;status/&gt;
        &lt;/product&gt;
      &lt;/products&gt;
    &lt;/delivery&gt;
    &lt;delivery&gt;
      &lt;code&gt;135834675500056751&lt;/code&gt;
      &lt;order_id&gt;400003&lt;/order_id&gt;
      &lt;status&gt;New&lt;/status&gt;
      &lt;payment_status/&gt;
      &lt;vozvrat_status/&gt; 
      &lt;errors/&gt;
      &lt;pickup_id/&gt;
      &lt;oplacheno_poluchatelem&gt;0&lt;/oplacheno_poluchatelem&gt; 
      &lt;products&gt;
        &lt;product&gt;
          &lt;articul&gt;22229-22&lt;/articul&gt;
          &lt;name&gt;test name&lt;/name&gt;
          &lt;quantity&gt;40&lt;/quantity&gt;
          &lt;price&gt;4000&lt;/price&gt;
          &lt;number_of_return&gt;0&lt;/number_of_return&gt;
          &lt;number_of_delivered&gt;0&lt;/number_of_delivered&gt;
          &lt;status/&gt;
        &lt;/product&gt;
        &lt;product&gt;
          &lt;articul&gt;4556-44&lt;/articul&gt;
          &lt;name&gt;test name&lt;/name&gt;
          &lt;quantity&gt;30&lt;/quantity&gt;
          &lt;price&gt;3000&lt;/price&gt;
          &lt;number_of_return&gt;0&lt;/number_of_return&gt;
          &lt;number_of_delivered&gt;0&lt;/number_of_delivered&gt;
          &lt;status/&gt;
        &lt;/product&gt;
      &lt;/products&gt;
    &lt;/delivery&gt;
    &lt;delivery&gt;
      &lt;code&gt;135833991800056758&lt;/code&gt;
      &lt;order_id&gt;600003&lt;/order_id&gt;
      &lt;status&gt;Completed&lt;/status&gt;
      &lt;payment_status/&gt;
      &lt;errors&gt;&lt;/errors&gt;
      &lt;pickup_id/&gt;
      &lt;oplacheno_poluchatelem&gt;0&lt;/oplacheno_poluchatelem&gt;
    &lt;/delivery&gt;
  &lt;/deliveries&gt;
&lt;/answer&gt;
</code></pre>

<p>Here is my testing php file (testcurl.php which I try to run from my site) using testing api_id / url:</p>

<pre><code>&lt;?php

// build xml        
$xml = '
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;file&gt;
&lt;request&gt;
  &lt;function&gt;get_order_status_array&lt;/function&gt;
  &lt;api_id&gt;577888574a3e4df01867cd5ccc9f18a5&lt;/api_id&gt;
  &lt;deliveries&gt;
    &lt;code&gt;135834675500056751&lt;/code&gt;
    &lt;code&gt;135834675500056750&lt;/code&gt;
    &lt;code&gt;135833991800056758&lt;/code&gt;
  &lt;/deliveries&gt;
&lt;/request&gt;
&lt;/file&gt;';

       $curl = curl_init();
       curl_setopt($curl, CURLOPT_URL, 'https://test.client-shop-logistics.ru/index.php?route=deliveries/api');
       curl_setopt($curl, CURLOPT_POST, 1);
       curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt($curl, CURLOPT_POSTFIELDS, 'xml='.urlencode(base64_encode($xml)));
       curl_setopt($curl, CURLOPT_USERAGENT, 'Opera 10.00');
       $res = curl_exec($curl);
       curl_close($curl);

       echo $res;

?&gt;
</code></pre>

<p>Finally I get an error: "Error in structure xml or wrong encoded decoded: get_order_status_array 577888574a3e4df01867cd5ccc9f18a5 135834675500056751 135834675500056750 135833991800056758"</p>

<p>What I am missing?   </p>