0

I'm trying to create an XML object via an xml string passed from unity to a url (eg. gamedata.php).

Method : POST

Now this is what happens.

via web browser : If i pass the string via the web browser (by changing the method to _REQUEST in php) it successfully creates the xml object and executes all the required scripts & queries.

via the build (unity) : When the same xml string is passed through the game, it throws an error Call to a member function asXML() on string in /var/www/html/

Below is the code

$myXMLData = trim($_POST['xml']); 

$xml=simplexml_load_string($myXMLData) or die("Error: Cannot create object");

$xml->asXML();

So Unity's debug console receives Error : Cannot create object & the log throws the error mentioned above.

XML passed

<?xml version="1.0" encoding="UTF-8" standalone="no"?><root><player id="3" avatar="m"><scenarios><scenario id="1" attempts="12" score="14" completed="" time=""><badges><badge id="1" icon="badges-icon"><title>Badge Title 01</title><description>Badge Text 01</description></badge><badge id="2" icon="badges-icon"><title>Badge Title 02</title><description>Badge Text 02</description></badge></badges><warnings><warning id="7" icon="badges-icon"><title>Warning Title 01</title><description>Warning Text 01</description></warning></warnings></scenario><scenario id="2" attempts="8" score="120" completed="" time=""><badges><badge id="6" icon="badges-icon"><title>Badge Title 09</title><description>Badge Text 09</description></badge></badges><warnings><warning id="8" icon="badges-icon"><title>Warning Title 03</title><description>Warning Text 03</description></warning></warnings></scenario></scenarios></player></root>

Can anyone help me out with this?

Dalton Pereira
  • 1,061
  • 1
  • 9
  • 14
  • Can you post the actual string you're passing? Also, are you escaping the url using WWW.EscapeURL(string)? – Venkat at Axiom Studios Aug 17 '15 at 13:16
  • Hey @VenkatatAxiomStudios I have updated the question with the xml string passed. and no i am not doing WWW.EscapeURL(string) – Dalton Pereira Aug 17 '15 at 13:23
  • Try posting with WWW.EscapeURL. What it does is create a url friendly string from your input string. Hopefully that fixes the issue – Venkat at Axiom Studios Aug 17 '15 at 13:40
  • About the XML string you quoted: is your server receiving that exact string from both clients? If not, how are they different? – rutter Aug 17 '15 at 15:51
  • I don't know Unity, but if it passes the XML as the HTTP request body with that POST request, take a look at this question which shows how you access the data then: [How to get body of a POST in php?](http://stackoverflow.com/q/8945879/367456) – hakre Aug 18 '15 at 18:23

0 Answers0