mysql - get method doesnt work on php rest web service -
excuse me,i try make restful web service request method post , get, success getmethod view data on mysql, when use post method search data or delete data post method doesnt work. dont know why... chek out
private function users(){ // cross validation if request method else return "not acceptable" status if($this->get_request_method() != "get") { $this->response('',406); } $sql = mysql_query("select user_id, user_fullname, user_email users user_status = 1", $this->db); if(mysql_num_rows($sql) > 0) { $result = array(); while($rlt = mysql_fetch_array($sql,mysql_assoc)){ $result[] = $rlt; } // if success everythig send header "ok" , return list of users in json format $this->response($this->json($result), 200); } $this->response('',204); // if no records "no content" status }
then delete method
private function deleteuser() { // cross validation if request method delete else return "not acceptable" status if($this->get_request_method() != "delete"){ $this->response('',406); } $id = (int)$this->_request['id']; if($id > 0) { mysql_query("delete users user_id = $id"); $success = array('status' => "success", "msg" => "successfully 1 record deleted."); $this->response($this->json($success),200); } else $this->response('',204); // if no records "no content" status }
your users() , deleteuser() functions check request_method of , delete respectively. therefore, if either of functions called when post done, both return 406
.
update: in answer of comment: should fix that?
if same functions expected work post, respective primary request_method, need allow post request method validated.
private function users(){ // cross validation if request method else return "not acceptable" status if ($this->get_request_method() != 'get' && $this->get_request_method() != 'post') { $this->response('',406); }
and
private function deleteuser() { // cross validation if request method delete else return "not acceptable" status if ($this->get_request_method() != 'delete' && $this->get_request_method() != 'post') { $this->response('',406); }
for deleteuser
function, i'm assuming $this->_request
sourced $_request, , can pick id
query string or form post.
since you've shown these 2 functions, can't sure there isn't other code redirect action somewhere else, if request post.
Comments
Post a Comment