Hi, I am trying to implement a RESTful web service in Cake 1.2 (RC2) that could receive XML content through HTTP POST and basically add that content as a new row to a db (through a basic simple model) or updating an existing one (HTTP PUT).
I have managed to read data from db and pushing that out as XML when client is issuing HTTP GET to url http://mydomain.com/recipes/index.xml and http://mydomain.com/recipes/view/1.xml following instructions in the CakePHP Cookbook (1.2), in chapter 4.10.1. However, I can't get the application to receive any content/XML data when submitting via HTTP POST into either http://mydomain.com/recipes/ or http://mydomain.com/recipes/add.xml. It says in the cookbook: "Creating the logic for the edit action is a bit trickier, but not by much. Since you're providing an API that outputs XML, it's a natural choice to receive XML as input. Not to worry, however: the RequestHandler and Router classes make things much easier. If a POST or PUT request has an XML content-type, then the input is taken and passed to an instance of Cake's Xml object, which is assigned to the $data property of the controller. Because of this feature, handling XML and POST data in parallel is seamless: no changes are required to the controller or model code. Everything you need should end up in $this->data." Everything else works, the right controller action is called, but $this->data array is always empty (both in POST/add and PUT/edit) so no XML is getting unserialized there. I have defined the following things: 1) app/config/routes.php Router::mapResources('Recipes'); Router::parseExtensions(); 2) app/controllers/recipes_controller.php var $components = array('RequestHandler'); ... function add() { $this->log('--- Add called! ---', LOG_DEBUG); $this->log('requestedWith: '.$this->RequestHandler->requestedWith(), LOG_DEBUG); $this->log('isXml: '.$this->RequestHandler->isXml(), LOG_DEBUG); $this->log('responseType: '.$this->RequestHandler->responseType(), LOG_DEBUG); $this->log('isPost: '.$this->RequestHandler->isPost(), LOG_DEBUG); $this->log('data: '.empty($this->data), LOG_DEBUG); if (!empty($this->data)) { $this->Recipe->create(); if($this->Recipe->save($this->data)) { $message = "Added OK!"; } else { $message = "Error!"; } $this->set(compact("message")); } 3) app/views/recipes/xml/add.ctp <message> <?php if(isset($message)) echo $message; ?> </message> I use RESTClient 2.1 (Wiztools.org) to test the application. I am trying to send the following xml data using HTTP POST Method to the controller, Content-type being application/xml; charset=UTF-8: <?xml version="1.0" encoding="UTF-8" ?> <recipe description="my recipe"> </recipe> I receive an empty xml response ("<?xml version="1.0" encoding="UTF-8" ?><message></message>") and application writes to the debug.log the following lines (data being empty): 2008-07-01 18:52:27 Debug: --- Add called! --- 2008-07-01 18:52:27 Debug: requestedWith: application/xml; charset=UTF-8 2008-07-01 18:52:27 Debug: isXml: xml 2008-07-01 18:52:27 Debug: responseType: xml 2008-07-01 18:52:27 Debug: isPost: 1 2008-07-01 18:52:27 Debug: data: 1 Has anybody encountered these kind of problems or tried to implement this? I am using CakePHP 1.2.0.7296 RC2, although I have created the app skeleton with 1.2 RC 1. Any pointers on what things should I check? Thanks and regards. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---