3
我通過API中的REST客戶端發送的PUT和POST請求之間存在差異。它使用Phil Sturgeon的REST服務器在CodeIgniter中實現。通過在CodeIgniter(Phil Sturgeon Rest Server)中發送PUT請求來插入數據
function station_put(){
$data = array(
'name' => $this->input->post('name'),
'number' => $this->input->post('number'),
'longitude' => $this->input->post('longitude'),
'lat' => $this->input->post('latitude'),
'typecode' => $this->input->post('typecode'),
'description' => $this->input->post('description'),
'height' => $this->input->post('height'),
'mult' => $this->input->post('mult'),
'exp' => $this->input->post('exp'),
'elevation' => $this->input->post('elevation')
);
$id_returned = $this->station_model->add_station($data);
$this->response(array('id'=>$id_returned,'message'=>"Successfully created."),201);
}
該請求成功地將數據插入到服務器中但是 - 它呈現除ID之外的其餘值NULL。
但是,如果將函數名稱更改爲station_post,它會正確插入數據。
有人請指出爲什麼PUT請求不起作用?我正在使用谷歌瀏覽器的最新版本。
Btw此API將被集成到BackBone處理的應用程序。我真的需要使用PUT嗎?或者在使用post的時候,骨幹中的模型保存功能還有另一種解決方法嗎?
對不起,我怕我犯了一個非常致命的錯誤。 如果要調用put請求而不是POST,數據數組必須包含$ this-> input-> put()。 –
Jekk
仍然無法正常工作。也許PUT不被支持。你怎麼看待人? – Jekk
終於回答了。而不是$ this-> input-> post或$ this-> input-> put,它必須是$ this-> put或$ this-> post,因爲數據不是來自表單。 – Jekk