Jump to content

Webservices : Fatal error (XML response is not parsable)


Recommended Posts

Bonjour à tous,

 

Je migre actuellement un Prestashop 1.4 vers la 1.5.6.2.

Sur cette boutique j'ai un script de mise à jour de statut de commande par les webservices.

 

Au moment d'ajouter l'enregistrement dans la table le script me retourne une Fatal error avec ce message :

HTTP XML response is not parsable: array ( 0 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 4, 'column' => 1, 'message' => 'Start tag expected, \'<\' not found ', 'file' => '', 'line' => 1, )), )

Voici mon code :

try
        {    
            // Instancie l'objet
            $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
            // Récupération du schema de la table
            $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/order_histories?schema=blank'));
            $resources = $xml->children()->children();
        }
        
        catch (PrestaShopWebserviceException $e)
        {
            // Here we are dealing with errors
            $trace = $e->getTrace();
            if ($trace[0]['args'][0] == 404) echo 'Bad ID';
            else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
            else echo 'Other error:'.$trace[0]['args'][0];
        }
        
        // Array contenant les infos pour la création
        $infos = array(
        'id_employee' => '4',
        'id_order' => $_GET['id'],
        'id_order_state' => $_GET['ns'],
        'date_add' => date('Y-m-d H:i:s')
        );
        foreach ( $resources as $nodeKey => $node ) {
          if (isset($infos[ $nodeKey ]))
          $resources->$nodeKey = $infos[ $nodeKey ];
        }
        
        try
        {    
            // Mise à jour des données    
            $opt = array('resource' => 'order_histories');
            $opt['postXml'] = $xml->asXML();
            $xml = $webService->add($opt);
            
            // Si webService ne revoie pas d'exception on affiche le résultat
            echo "**MAJ OK**";
            echo "<br />";
         }

        catch (PrestaShopWebserviceException $e)
        {
            // Here we are dealing with errors
            $trace = $e->getTrace();
            if ($trace[0]['args'][0] == 404) echo 'Bad ID';
            else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
            else echo 'Other error:'.$trace[0]['args'][0].'<br />'.$e->getMessage();
        }

Tout marche bien jusqu'à la ligne : $xml = $webService->add($opt);

 

PHP tourne en FastCGI et Curl est activé, la sortie donne :


HTTP REQUEST HEADER

GET /api/order_histories?schema=blank HTTP/1.1
Authorization: Basic SE00QkVUT1IxSVJBVk9VNU00QTgxTFJIV0JITlc4VjM6
Host: www.monsite.com
Accept: */*

HTTP RESPONSE HEADER

HTTP/1.1 200 OK
Server: nginx
Date: Fri, 07 Mar 2014 13:11:44 GMT
Content-Type: text/xml;charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Time: 1394197904
PSWS-Version: 1.5.6.2
Execution-Time: 0.005
Content-Sha1: ee88ce98ad5536610bb854800ca757f339dedfe6
Set-Cookie: 5a2c67b4928ffe5745bb882ad7942d17=32N2gmbRt1PWKAodAi0M%2FnQV1Aa92wPzSgs%2BJDCo99kEaXVYPAiBh6%2Fw5lUHkFCsCKjasKWIZlqrw4om%2ByGWZ%2BDAS6%2F%2F2POhS%2B9D%2FYnxa%2Fw%3D000078; expires=Thu, 27-Mar-2014 13:11:44 GMT; path=/; domain=www.monsite.com; httponly
Vary: Authorization,Host,Accept-Encoding
X-Powered-By: PleskLin
MS-Author-Via: DAV
Pragma: no-cache

RETURN HTTP BODY

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<order_history>
	<id></id>
	<id_order_state></id_order_state>
	<id_order></id_order>
	<id_employee></id_employee>
	<date_add></date_add>
</order_history>
</prestashop>

HTTP REQUEST HEADER

POST //api/order_histories HTTP/1.1
Authorization: Basic SE00QkVUT1IxSVJBVk9VNU00QTgxTFJIV0JITlc4VjM6
Host: www.monsite.com
Accept: */*
Content-Length: 288
Content-Type: application/x-www-form-urlencoded

HTTP RESPONSE HEADER

HTTP/1.1 200 OK
Server: nginx
Date: Fri, 07 Mar 2014 13:11:44 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: 5a2c67b4928ffe5745bb882ad7942d17=32N2gmbRt1PWKAodAi0M%2FnQV1Aa92wPzSgs%2BJDCo99kEaXVYPAiBh6%2Fw5lUHkFCsCKjasKWIZlqrw4om%2ByGWZ%2BDAS6%2F%2F2POhS%2B9D%2FYnxa%2Fw%3D000078; expires=Thu, 27-Mar-2014 13:11:44 GMT; path=/; domain=www.monsite.com; httponly
Vary: Authorization,Host,Accept-Encoding
X-Powered-By: PleskLin
MS-Author-Via: DAV
Pragma: no-cache

XML SENT

xml=<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<order_history>
	<id/>
	<id_order_state>6</id_order_state>
	<id_order>2380</id_order>
	<id_employee>4</id_employee>
	<date_add>2014-03-07 14:11:44</date_add>
</order_history>
</prestashop>

RETURN HTTP BODY

Fatal error

Other error:Fatal error
HTTP XML response is not parsable: array ( 0 => LibXMLError::__set_state(array( 'level' => 3, 'code' => 4, 'column' => 1, 'message' => 'Start tag expected, \'<\' not found ', 'file' => '', 'line' => 1, )), )

J'ai parcouru pas mal de posts, fait des recherches et pas mal d'essais mais je ne trouve pas la cause.

Si quelqu'un a une idée, je prends :P

 

A+

Edited by Pascal - Netenvie (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...
  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...