HTTP XML响应不可解析:仅在文档开头允许XML声明

时间:2017-07-11 14:21:42

标签: php xml web-services prestashop

我正在使用PrestaShop添加新订单但在最后一步中我收到以下错误:

    Other error 
    HTTP XML response is not parsable: array ( 
      0 =>
      LibXMLError::__set_state(array(
         'level' => 3, 
         'code' => 64, 
         'column' => 7, 
         'message' => 'XML declaration allowed only at the start of the document ', 
         'file' => '', 
         'line' => 1, 
      )), 
    )

这是回复:

>   HTTP REQUEST HEADER
> 
> POST //api/orders HTTP/1.1 Authorization: Basic
> NzQzTlJUVDgxMlJHTDdHSVBXN0s3UENBVURHVklLUk06 Host: elpakhsh.com
> Accept: */* Content-Length: 1920 Content-Type:
> application/x-www-form-urlencoded
> 
> HTTP RESPONSE HEADER
> 
> HTTP/1.1 201 Created Date: Tue, 11 Jul 2017 14:14:51 GMT Server:
> Apache Access-Time: 1499782493 X-Powered-By: PrestaShop Webservice
> PSWS-Version: 1.6.1.0 Execution-Time: 1.958 Content-Sha1:
> 845e19c0e92215a30bf88b5d3133e889718ba5c7 Set-Cookie:
> PrestaShop-44660b7e8ec360eac31034d5f90f6f7b=R4%2FKd8PSworb4qQa5u4p4fGdEsCUFhmLcekrJ2xUWRSiUoNrT3PMDiMtnTf6u8Rkg2iiuntyRJCUx%2BwsE%2FpWXcHdN4mF%2FRnb8CypMWRQK5w%3D000079;
> expires=Mon, 31-Jul-2017 14:14:51 GMT; path=/; domain=elpakhsh.com;
> httponly Transfer-Encoding: chunked Content-Type:
> text/xml;charset=utf-8
> 
> XML SENT
> 
> <?xml version="1.0" encoding="UTF-8"?> <prestashop
> xmlns:xlink="http://www.w3.org/1999/xlink"> <order>   <id/>
>   <id_address_delivery>249</id_address_delivery>
>   <id_address_invoice>249</id_address_invoice>    <id_cart>450</id_cart>
>   <id_currency>1</id_currency>    <id_lang>2</id_lang>
>   <id_customer>202</id_customer>  <id_carrier>1</id_carrier>
>   <current_state></current_state>     <module>cashondelivery</module>
>   <invoice_number/>   <invoice_date/>     <delivery_number/>
>   <delivery_date/>    <valid>1</valid>    <date_add/>     <date_upd/>
>   <shipping_number/>  <id_shop_group/>    <id_shop/>  <secure_key/>
>   <payment>Cash on delivery</payment>     <recyclable/>   <gift/>
>   <gift_message/>     <mobile_theme/>     <total_discounts></total_discounts>
>   <total_discounts_tax_incl></total_discounts_tax_incl>
>   <total_discounts_tax_excl></total_discounts_tax_excl>
>   <total_paid>100</total_paid>
>   <total_paid_tax_incl></total_paid_tax_incl>
>   <total_paid_tax_excl></total_paid_tax_excl>
>   <total_paid_real>0</total_paid_real>
>   <total_products>100</total_products>
>   <total_products_wt>100</total_products_wt>
>   <total_shipping></total_shipping>
>   <total_shipping_tax_incl></total_shipping_tax_incl>
>   <total_shipping_tax_excl></total_shipping_tax_excl>
>   <carrier_tax_rate/>     <total_wrapping/>   <total_wrapping_tax_incl/>
>   <total_wrapping_tax_excl/>  <round_mode/>   <round_type/>
>   <conversion_rate>1</conversion_rate>    <reference/>    <visitorCheck/>
> <associations> <order_rows>   <order_row>     <id/>
>   <product_id>10104</product_id>  <product_attribute_id/>
>   <product_quantity>1</product_quantity>  <product_name>ک�سر�
> خ�ارک باد�جا� تبرک    
> 15000ر�ا�*20عدد</product_name>
>   <product_reference></product_reference>     <product_ean13/>
>   <product_upc/>  <product_price></product_price>
>   <unit_price_tax_incl></unit_price_tax_incl>
>   <unit_price_tax_excl></unit_price_tax_excl>     </order_row>
> </order_rows> </associations> </order> </prestashop>
> 
> RETURN HTTP BODY
> 
>  <?xml version="1.0" encoding="UTF-8"?> <prestashop
> xmlns:xlink="http://www.w3.org/1999/xlink"> <order>
>   <id><![CDATA[173]]></id>    <id_address_delivery
> xlink:href="http://elpakhsh.com/api/addresses/249"><![CDATA[249]]></id_address_delivery>
>   <id_address_invoice
> xlink:href="http://elpakhsh.com/api/addresses/249"><![CDATA[249]]></id_address_invoice>
>   <id_cart
> xlink:href="http://elpakhsh.com/api/carts/450"><![CDATA[450]]></id_cart>
>   <id_currency
> xlink:href="http://elpakhsh.com/api/currencies/1"><![CDATA[1]]></id_currency>
>   <id_lang
> xlink:href="http://elpakhsh.com/api/languages/2"><![CDATA[2]]></id_lang>
>   <id_customer
> xlink:href="http://elpakhsh.com/api/customers/202"><![CDATA[202]]></id_customer>  <id_carrier
> xlink:href="http://elpakhsh.com/api/carriers/1"><![CDATA[1]]></id_carrier>
>   <current_state xlink:href="http://elpakhsh.com/api/order_states/"
> notFilterable="true"></current_state>
>   <module><![CDATA[cashondelivery]]></module>
>   <invoice_number></invoice_number>   <invoice_date></invoice_date>
>   <delivery_number></delivery_number>     <delivery_date></delivery_date>
>   <valid><![CDATA[1]]></valid>    <date_add></date_add>
>   <date_upd></date_upd>   <shipping_number
> notFilterable="true"></shipping_number>
>   <id_shop_group></id_shop_group>     <id_shop></id_shop>
>   <secure_key></secure_key>   <payment><![CDATA[Cash on
> delivery]]></payment>     <recyclable></recyclable>   <gift></gift>
>   <gift_message></gift_message>   <mobile_theme></mobile_theme>
>   <total_discounts></total_discounts>
>   <total_discounts_tax_incl></total_discounts_tax_incl>
>   <total_discounts_tax_excl></total_discounts_tax_excl>
>   <total_paid><![CDATA[100]]></total_paid>
>   <total_paid_tax_incl></total_paid_tax_incl>
>   <total_paid_tax_excl></total_paid_tax_excl>
>   <total_paid_real><![CDATA[0]]></total_paid_real>
>   <total_products><![CDATA[100]]></total_products>
>   <total_products_wt><![CDATA[100]]></total_products_wt>
>   <total_shipping></total_shipping>
>   <total_shipping_tax_incl></total_shipping_tax_incl>
>   <total_shipping_tax_excl></total_shipping_tax_excl>
>   <carrier_tax_rate></carrier_tax_rate>
>   <total_wrapping></total_wrapping>
>   <total_wrapping_tax_incl></total_wrapping_tax_incl>
>   <total_wrapping_tax_excl></total_wrapping_tax_excl>
>   <round_mode></round_mode>   <round_type></round_type>
>   <conversion_rate><![CDATA[1]]></conversion_rate>
>   <reference></reference>     <visitorCheck></visitorCheck> <associations>
> <order_rows nodeType="order_row" virtualEntity="true">    <order_row>
>   <id><![CDATA[254]]></id>    <product_id><![CDATA[10104]]></product_id>
>   <product_attribute_id><![CDATA[0]]></product_attribute_id>
>   <product_quantity><![CDATA[1]]></product_quantity>
>   <product_name><![CDATA[ک�سر� خ�ارک باد�جا� تبرک 
> 15000ر�ا�*20عدد]]></product_name>
>   <product_reference><![CDATA[10104]]></product_reference>
>   <product_ean13><![CDATA[10104]]></product_ean13>
>   <product_upc><![CDATA[10104]]></product_upc>
>   <product_price><![CDATA[300000.000000]]></product_price>
>   <unit_price_tax_incl><![CDATA[240000.000000]]></unit_price_tax_incl>
>   <unit_price_tax_excl><![CDATA[240000.000000]]></unit_price_tax_excl>
>   </order_row> </order_rows> </associations> </order> </prestashop>

这与语言有什么关系吗?因为这是一个非英语网站。

1 个答案:

答案 0 :(得分:0)

作为Nigel states,很难确切地知道问题是什么,而没有看到实际的反应。但是,出现此错误的原因可能有很多:

XML declaration allowed only at the start of the document

有些原因是:

  • 确保响应开始时没有空格
  • 你只有一行开始

    <?xml version="1.0"...
    

    该行的多个副本将导致您看到的错误。

  • Unicode文件头 - 检查XML的编码

请参阅Problem - XML declaration allowed only at the start of the document