开发者

Creating a RESTful service in CakePHP

I'm attempting to create a RESTful service in CakePHP but I've hit a bit of a brick wall.

I've enabled the default RESTful routing using Router::mapResources('users') and Router::parseExtensions(). This works well if I make a GET request, and returns some nicely formatted XML. So far so good.

The problem is if I want to make a POST or PUT request. CakePHP doesn't seem to be able to read the data from the request. At the moment my add(), edit() and delete() actions don't contain any logic, they're simply setting $this->data to t开发者_开发知识库he view.

I'm testing with the following cURL command:

curl -v -d "<user><username>blahblah</username><password>blahblah</password>" http://localhost/users.xml --header 'content-type: text/xml'

Which only returns a 404 header. If I remove the --header parameter then it returns the view but no data is set.

It feels like I'm missing something obvious here. Any ideas?


Solved: In the $components array in the controller, 'Security' needed to be placed before 'RequestHandler'. SecurityComponent was going in and Blackholeing all of my requests after RequestHandler had done its thing. I think.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜