Jump to content

Problem using webservice from external application (XML error : String could not be parsed as XML)


mitsos1os

Recommended Posts

Hi, I am developping an application to interact with Prestashop's Webservice. I can get data without any problem through HTTP Requests that return to me the wanted XML. My problem is when I try to update a customer for example with a PUT Request.

I get the XML of the customer, convert it to string, and try to send it through an http form. But I get the XML 127 error that the string could not be parsed as XML

 

XML I Get:

 

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink"><customer><id><![CDATA[3]]></id><id_default_group xlink:href="http://192.168.10.6/discontopre2/api/groups/3"><![CDATA[3]]></id_default_group><id_lang xlink:href="http://192.168.10.6/discontopre2/api/languages/7"><![CDATA[7]]></id_lang><newsletter_date_add><![CDATA[0000-00-00 00:00:00]]></newsletter_date_add><ip_registration_newsletter/><last_passwd_gen><![CDATA[2013-04-02 09:40:57]]></last_passwd_gen><secure_key><![CDATA[c9bf8c7eaa139235374cbe556af2f516]]></secure_key><deleted><![CDATA[0]]></deleted><passwd><![CDATA[eebda79069f1432169d897f9ddd94673]]></passwd><lastname><![CDATA[Χαλάτσης]]></lastname><firstname><![CDATA[Mitsos]]></firstname><email><![CDATA[[email protected]]]></email><id_gender><![CDATA[1]]></id_gender><birthday><![CDATA[0000-00-00]]></birthday><newsletter><![CDATA[0]]></newsletter><optin><![CDATA[0]]></optin><website/><company/><siret/><ape/><outstanding_allow_amount><![CDATA[0.000000]]></outstanding_allow_amount><show_public_prices><![CDATA[0]]></show_public_prices><id_risk><![CDATA[0]]></id_risk><max_payment_days><![CDATA[0]]></max_payment_days><active><![CDATA[1]]></active><note/><is_guest><![CDATA[0]]></is_guest><id_shop><![CDATA[1]]></id_shop><id_shop_group><![CDATA[1]]></id_shop_group><date_add><![CDATA[2013-04-02 15:40:57]]></date_add><date_upd><![CDATA[2013-04-25 18:09:18]]></date_upd><associations><groups node_type="group"><group xlink:href="http://192.168.10.6/discontopre2/api/groups/3"><id><![CDATA[3]]></id></group></groups></associations></customer></prestashop>

 

 

I try to send it either as a file attached with type "text/xml" from an Http Form and I get this response...

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<code><![CDATA[127]]></code>
<message><![CDATA[xml error : String could not be parsed as XML
XML length : 1748
Original XML :
--WDFormBoundary
Content-Disposition: form-data; name="xml"; filename="temp.xml"
Content-Type: text/xml
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink"><customer><id><![CDATA[3]]></id><id_default_group xlink:href="http://192.168.10.6/discontopre2/api/groups/3"><![CDATA[3]]></id_default_group><id_lang xlink:href="http://192.168.10.6/discontopre2/api/languages/7"><![CDATA[7]]></id_lang><newsletter_date_add><![CDATA[0000-00-00 00:00:00]]></newsletter_date_add><ip_registration_newsletter/><last_passwd_gen><![CDATA[2013-04-02 09:40:57]]></last_passwd_gen><secure_key><![CDATA[c9bf8c7eaa139235374cbe556af2f516]]></secure_key><deleted><![CDATA[0]]></deleted><passwd><![CDATA[eebda79069f1432169d897f9ddd94673]]></passwd><lastname><![CDATA[?a??ts??]]></lastname><firstname><![CDATA[Mitsos]]></firstname><email><![CDATA[[email protected]]]></email><id_gender><![CDATA[1]]></id_gender><birthday><![CDATA[0000-00-00]]></birthday><newsletter><![CDATA[0]]></newsletter><optin><![CDATA[0]]></optin><website/><company/><siret/><ape/><outstanding_allow_amount><![CDATA[0.000000]]></outstanding_allow_amount><show_public_prices><![CDATA[0]]></show_public_prices><id_risk><![CDATA[0]]></id_risk><max_payment_days><![CDATA[0]]></max_payment_days><active><![CDATA[1]]></active><note/><is_guest><![CDATA[0]]></is_guest><id_shop><![CDATA[1]]></id_shop><id_shop_group><![CDATA[1]]></id_shop_group><date_add><![CDATA[2013-04-02 15:40:57]]></date_add><date_upd><![CDATA[2013-04-25 18:09:18]]></date_upd><associations><groups node_type="group"><group xlink:href="http://192.168.10.6/discontopre2/api/groups/3"><id><![CDATA[3]]></id></group></groups></associations></customer></prestashop>
--WDFormBoundary--]]></message>
</error>
</errors>
</prestashop>

 

 

And I also try to send it as a parameter of the form named "xml" and I get this response:

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<code><![CDATA[127]]></code>
<message><![CDATA[xml error : String could not be parsed as XML
XML length : 2864
Original XML : xml=%3C%3Fxml+version%3D%221%2E0%22+encoding%3D%22UTF%2D8%22%3F%3E%0A%3Cprestashop+xmlns%3Axlink%3D%22http%3A%2F%2Fwww%2Ew3%2Eorg%2F1999%2Fxlink%22%3E%0A%3Ccustomer%3E%0A%09%3Cid%3E%3C%21%5BCDATA%5B3%5D%5D%3E%3C%2Fid%3E%0A%09%3Cid%5Fdefault%5Fgroup+xlink%3Ahref%3D%22http%3A%2F%2F192%2E168%2E10%2E6%2Fdiscontopre2%2Fapi%2Fgroups%2F3%22%3E%3C%21%5BCDATA%5B3%5D%5D%3E%3C%2Fid%5Fdefault%5Fgroup%3E%0A%09%3Cid%5Flang+xlink%3Ahref%3D%22http%3A%2F%2F192%2E168%2E10%2E6%2Fdiscontopre2%2Fapi%2Flanguages%2F7%22%3E%3C%21%5BCDATA%5B7%5D%5D%3E%3C%2Fid%5Flang%3E%0A%09%3Cnewsletter%5Fdate%5Fadd%3E%3C%21%5BCDATA%5B0000%2D00%2D00+00%3A00%3A00%5D%5D%3E%3C%2Fnewsletter%5Fdate%5Fadd%3E%0A%09%3Cip%5Fregistration%5Fnewsletter%2F%3E%0A%09%3Clast%5Fpasswd%5Fgen%3E%3C%21%5BCDATA%5B2013%2D04%2D02+09%3A40%3A57%5D%5D%3E%3C%2Flast%5Fpasswd%5Fgen%3E%0A%09%3Csecure%5Fkey%3E%3C%21%5BCDATA%5Bc9bf8c7eaa139235374cbe556af2f516%5D%5D%3E%3C%2Fsecure%5Fkey%3E%0A%09%3Cdeleted%3E%3C%21%5BCDATA%5B0%5D%5D%3E%3C%2Fdeleted%3E%0A%09%3Cpasswd%3E%3C%21%5BCDATA%5Beebda79069f1432169d897f9ddd94673%5D%5D%3E%3C%2Fpasswd%3E%0A%09%3Clastname%3E%3C%21%5BCDATA%5B%CE%A7%CE%B1%CE%BB%CE%AC%CF%84%CF%83%CE%B7%CF%82%5D%5D%3E%3C%2Flastname%3E%0A%09%3Cfirstname%3E%3C%21%5BCDATA%5BMitsos%5D%5D%3E%3C%2Ffirstname%3E%0A%09%3Cemail%3E%3C%21%5BCDATA%5Bdimitrisx%40moi%2Egr%5D%5D%3E%3C%2Femail%3E%0A%09%3Cid%5Fgender%3E%3C%21%5BCDATA%5B1%5D%5D%3E%3C%2Fid%5Fgender%3E%0A%09%3Cbirthday%3E%3C%21%5BCDATA%5B0000%2D00%2D00%5D%5D%3E%3C%2Fbirthday%3E%0A%09%3Cnewsletter%3E%3C%21%5BCDATA%5B0%5D%5D%3E%3C%2Fnewsletter%3E%0A%09%3Coptin%3E%3C%21%5BCDATA%5B0%5D%5D%3E%3C%2Foptin%3E%0A%09%3Cwebsite%2F%3E%0A%09%3Ccompany%2F%3E%0A%09%3Csiret%2F%3E%0A%09%3Cape%2F%3E%0A%09%3Coutstanding%5Fallow%5Famount%3E%3C%21%5BCDATA%5B0%2E000000%5D%5D%3E%3C%2Foutstanding%5Fallow%5Famount%3E%0A%09%3Cshow%5Fpublic%5Fprices%3E%3C%21%5BCDATA%5B0%5D%5D%3E%3C%2Fshow%5Fpublic%5Fprices%3E%0A%09%3Cid%5Frisk%3E%3C%21%5BCDATA%5B0%5D%5D%3E%3C%2Fid%5Frisk%3E%0A%09%3Cmax%5Fpayment%5Fdays%3E%3C%21%5BCDATA%5B0%5D%5D%3E%3C%2Fmax%5Fpayment%5Fdays%3E%0A%09%3Cactive%3E%3C%21%5BCDATA%5B1%5D%5D%3E%3C%2Factive%3E%0A%09%3Cnote%2F%3E%0A%09%3Cis%5Fguest%3E%3C%21%5BCDATA%5B0%5D%5D%3E%3C%2Fis%5Fguest%3E%0A%09%3Cid%5Fshop%3E%3C%21%5BCDATA%5B1%5D%5D%3E%3C%2Fid%5Fshop%3E%0A%09%3Cid%5Fshop%5Fgroup%3E%3C%21%5BCDATA%5B1%5D%5D%3E%3C%2Fid%5Fshop%5Fgroup%3E%0A%09%3Cdate%5Fadd%3E%3C%21%5BCDATA%5B2013%2D04%2D02+15%3A40%3A57%5D%5D%3E%3C%2Fdate%5Fadd%3E%0A%09%3Cdate%5Fupd%3E%3C%21%5BCDATA%5B2013%2D04%2D25+18%3A09%3A18%5D%5D%3E%3C%2Fdate%5Fupd%3E%0A%3Cassociations%3E%0A%3Cgroups+node%5Ftype%3D%22group%22%3E%0A%09%3Cgroup+xlink%3Ahref%3D%22http%3A%2F%2F192%2E168%2E10%2E6%2Fdiscontopre2%2Fapi%2Fgroups%2F3%22%3E%0A%09%3Cid%3E%3C%21%5BCDATA%5B3%5D%5D%3E%3C%2Fid%3E%0A%09%3C%2Fgroup%3E%0A%3C%2Fgroups%3E%0A%3C%2Fassociations%3E%0A%3C%2Fcustomer%3E%0A%3C%2Fprestashop%3E%0A]]></message>
</error>
</errors>
</prestashop>

 

Any help appreciated.

Edited by mitsos1os (see edit history)
Link to comment
Share on other sites

  • 3 months later...

Can you please explain how you added a parameter without a name? If I do that I get the same response except

Original XML : xml=%3C%3Fxml+version%3D%221%2E0%22+encoding...

is now

Original XML : =%3C%3Fxml+version%3D%221%2E0%22+encoding...

 

Edit: I forgot to mention that I work with C#.

Edited by petter386 (see edit history)
Link to comment
Share on other sites

  • 1 year later...

Hi everyone,

 

For more, I had the same issue with POST command. I am also using Windev IDE (WD16) with different Prestashop versions (1.4, 1.5 and 1.6).

This error just happend with 1.6 sites. I solved it as explained by mitsos1os on changing the HTTPAddParameter command :

- HTTPAddParameter(<form name>,"",<param value>)

I changed too the send command and replaced the content type by "text/xml" :

- HTTPSendForm(<form name>,<URL>,httpPost,<User agent>,"","text/xml; charset=""utf-8""",<user>,<password>)

I just delivered my fix to test team and I pray for a validation ...

Link to comment
Share on other sites

  • 1 year 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...