How to send a post request to the RESTserver api in php-Codeigniter? How to send a post request to the RESTserver api in php-Codeigniter? codeigniter codeigniter

How to send a post request to the RESTserver api in php-Codeigniter?


Finally I came up with a solution, I used PHP cURL to send a post request to my RESTserver.

Here is my RESTclient POST request

 $data = array(            'patient_id'      => '1',            'department_name' => 'a',            'patient_type'    => 'b'    );    $data_string = json_encode($data);    $curl = curl_init('http://localhost/patient-portal/api/patient/visit');    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");    curl_setopt($curl, CURLOPT_HTTPHEADER, array(    'Content-Type: application/json',    'Content-Length: ' . strlen($data_string))    );    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);  // Make it so the data coming back is put into a string    curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);  // Insert the data    // Send the request    $result = curl_exec($curl);    // Free up the resources $curl is using    curl_close($curl);    echo $result;


you may debug your code. try to print Global variable $_POST.and I think this may solve your problemjust use $this->input->post instead of instead of $this->post