dongqiangse6623 2016-12-09 20:21
浏览 17

php cURL - post和echo result:“xml结构错误或编码解码错误...”

I try to post and get result by cURL, with no success yet...

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:

   $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);

Request example:

<request>
  <function>get_order_status_array</function>
  <api_id>API_ID</api_id>
  <deliveries>
    <code>135834675500056751</code>
    <code>135834675500056750</code>
    <code>135833991800056758</code>
  </deliveries>
</request>

Answer example:

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

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

<?php

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

       $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;

?>

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

What I am missing?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测