Tom*_*mer 12 php rest codeigniter
正如标题所说,我正在使用Codeigniter和phil sturgeon - codeigniter-restserver框架.
我已经按照Nettus上的教程进行操作,除了发送DELETE请求时,一切正常.
码:
<?php
require(APPPATH.'libraries/REST_Controller.php');
class Client extends REST_Controller{
function user_get()
{
$data = array('returned:'=> $this->get('id'));
$this->response($data);
}
function user_post()
{
$data = array('returned:'=> $this->post('id'));
$this->response($data);
}
function user_put()
{
$data = array('returned:'=> $this->put('id'));
$this->response($data);
}
function user_delete()
{
$data = array('returned from delete:'=> $this->delete('id'));
$this->response($data);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用一个名为HTTP Resource test的FF Addon来发送请求,但是当我发送带有此URL的DELETE请求时http://localhost/api/client/user/id/1,我得到{"从delete中返回:":false}
作为旁注:我发现这篇文章并使用'X-HTTP-Method-Override'标题并将其作为帖子请求发送我能够获得id,但我更喜欢客户端不必添加的方式这个标题.
Phi*_*eon 14
根据HTTP规范DELETE无法发送参数.它可以包含URL中的内容,因此您可以将其更改为:
public function user_delete($id)
{
$this->response(array(
'returned from delete:' => $id,
));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6560 次 |
| 最近记录: |