![]() |
Using XML-RPC class to respond to non-XML requests - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Using XML-RPC class to respond to non-XML requests (/showthread.php?tid=22822) |
Using XML-RPC class to respond to non-XML requests - El Forum - 09-21-2009 [eluser]oribani[/eluser] Hi, I was looking for a painless way to send XML back to a client who sent a simple/classic POST request (non-XML). Unfortunately, if you want to use the XML-RPC classes, it looks like you are locked into needing to have a XML request from the client in order to build and send a XML response. While a good alternative would be to use the JSON model, I have easy JavaScript that can quickly parse what I need from a simple XML response, so I dug into the XML-RPC class and pulled the code I needed to make one into a helper function that I wanted to share below. If there's a supported way to do this, I'd like to hear about it. Code: /** That "Pre-built CI xmlrpc response array" argument is easily created per the user guide documentation, but since its syntax is easy to trip over, I also abstracted it into an easy helper function (just note that it creates a structure that is specific to what my application does and my JavaScript that parses it): Code: /** So this way, my controller can validate POST data normally (with the form validator class) and send back a response in XML with a simple call to send_xml_response(...); |