php – 如何发送DELETE请求到phil sturgeon的 – codeigniter-re
发布时间:2020-12-13 14:02:00 所属栏目:PHP教程 来源:网络整理
导读:正如标题所说,我正在使用Codeigniter与phil sturgeon – codeigniter-restserver框架. 我遵循了Nettus的教程,一切正常,除非发送DELETE请求. 码: ?phprequire(APPPATH.'libraries/REST_Controller.php');class Client extends REST_Controller{function user
正如标题所说,我正在使用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中的东西,因此您可以将其更改为:
public function user_delete($id) { $this->response(array( 'returned from delete:' => $id,)); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |