I am attempting to interact with an API that requires sending and receiving an XML packet. The instruction in the API doc simply says: I've attempted to do this with various errors. I'm not sure if I'm even going about it in the right way. Here is my code: /** * Define POST URL and also payload */ $payload = 'foo_xml_input=<?xml version="1.0" encoding="UTF-8"?><foo username="uaer" password="pass" api="1"/>'; define('XML_SEND', $payload); define('XML_POST_URL', 'http://api.foo.com/api/getSiteIDs.cfm'); /** * Initialize handle and set options */ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, XML_POST_URL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_POSTFIELDS, XML_SEND); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close')); /** * Execute the locarequest and also time the transaction */ $start = array_sum(explode(' ', microtime())); $result = curl_exec($ch); $stop = array_sum(explode(' ', microtime())); $totalTime = $stop - $start; Code (markup): http://pastebin.com/909bgcUE Here is the current error I am getting: An error occured while Parsing an XML document. The entity name must immediately follow the '&' in the entity reference. Code (markup): Any help on what I might be doing wrong would be appreciated.
Thanks, I did that and ended up with the code you see above. But it doesn't work. When the API doc says "Wrap the following XML structure in a variable called ..." I assume it means a POST variable, but it doesn't specify further. I was hoping someone with experience working with APIs that communicate via XML would be able to recognize the problem.
Blast! They had an error on their end. They finally looked into it after several days of banging my head against the wall and fixed it. Everything works great now.