正如标题所说,我正在使用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); } }
我正在使用一个称为HTTP资源测试的FF Addon来发送请求,但是当我使用此URL发送DELETE请求时:http:// localhost / api / client / user / id / 1,我得到{“从删除返回:“:假}
作为附注:我发现这个post并使用’X-HTTP-Method-Override’标题,并将其作为发送请求发送,我能够获得id,但是我提供了一种客户端不必添加的方式这个标题.
根据HTTP规范DELETE不能发送参数.它可以在URL中的东西,因此您可以将其更改为:
原文链接:/php/139598.htmlpublic function user_delete($id) { $this->response(array( 'returned from delete:' => $id,)); }