Search code examples
xmlcurlcommand-linephp4

malformed XML returned by curl command line


I'm sending a string of XML tags and data in PHP to an API on another server that is expecting XML.

we are sending the string via command line like this

exec("curl http://addressToAPI.com/index.php?xml=$xml", $response);

$xml is the string of tags and pringoperties were sending to the API.

The API processes the string to XML fine and returns a response. However the $response which contains the returned success or failure xml is sent back as an array which doesnt include any of the XML tags.

Unfortunately we are sending the data as a string because the server is running PHP 4.3.9 without domxml extension and doesnt have PHP curl installed either. We cannot run it on another server and we cant upgrade the server due to other software running on it.

So since we need to work with this API we figured we could send the XML as a string (which seems to work fine) but its the response we get back just isn't returned as a string or xml.

We know the API server is returning XML as it logs every request and we can see the input document and returned response in its log.

Somehow it seems command line curl is changing the XML response to an array without tags.

Im hoping this makes some sense. Does anyone know away to get the XML reponse so we can retrieve the data successfully.


Solution

  • We figured out a solution to this. Im still unsure why the returned response is an array rathan just a string but managed to get it to include the tags in the array elements. We then use a foreach loop to pass each key of the array onto the end of a string.

    We then have the response we wanted.

    Apologies, I understand its hard for anyone to help without examples, especially when the problem isnt clear. It turned out to be one of them cases where you just needed to play with the code until you got the solution you wanted.

    Either way many thanks for your time in reading this post.