I recently encountered a painful problem when using restserver. I found that the parameters obtained by $this->put are all null. After checking, I found that this seems to be a common problem, see the link: https://github.com/chriskacerguis/codeigniter-restserver/issues/362
Let’s take a look at the official explanation first: see http://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter-2--net-8814
$this->put() Reads in PUT arguments set in the HTTP headers or via cURL.
1, consistent with post, still passing parameters in the body. Write a function in the base class:
public function getPut($key){ return $this->input->input_stream($key); }
$data = $this->getPut(array('tel', 'name', 'addr'));
Supplement: When putting parameters in the body, you can directly use $this->put() to get the corresponding fields. The document says it is in the headers, but it is actually in the body! However, $this->put() does not support multiple fields, so the above function is still meaningful.
$this->delete() also has this problem. The parameters in the headers cannot be read, but the parameters in the body can be read! ! !
2. The parameters are passed in the header and a function is written in the base class:
/** * 获得key对应的header * @param $key * @return mixed */ public function getHeader($key){ return $this->input->get_request_header($key, TRUE); }
ps: The problem that put in restserver cannot obtain parameters has nothing to do with the setting of Content-Type: application/json.