关于Restful API POST请求无数据
hi: 今日学习了一下PHP的Restful的请求,发现post拿到的数据为空,甚是不解,也找不出原因在哪。贴一下代码:
curl -l -H "Content-type: application/json" -X POST -d '{“start":0,"client":"1","deviceid":"63A94D37-33F9-40FF-9EBB-481182338873","limit":10,"auth":"XMdnEiW0m3qxDCMVzGMTikDJxQ8aoNbKF8W1rUDRicWP23tBNQhpd6fw","version":"3.0.1"}' http://localhost/pianke/index.php/api/pub/today
public function today_post() {
$params = json_decode(json)
$start = $this->input->post('start');
$limit = $this->input->post('limit');
$client = $this->input->post('client');
$deviceid = $this->input->post('deviceid');
$version = $this->input->post('version');
$this->response(array('start' => $start), REST_Controller::HTTP_OK);
}
拿到的start结果为null
你POST的是一个JSON字符串,不是标准FORM表单,使用 file_get_contents('php://input'),然后直接 json_decode
页:
[1]