CodeIgniter Passing POST data from RestClient to RestServer API CodeIgniter Passing POST data from RestClient to RestServer API codeigniter codeigniter

CodeIgniter Passing POST data from RestClient to RestServer API


Use this method to send Rest client data to rest server using post method. Read comment on every line

// initialize you setting      $config = array('server' => base_url() . "v1",            'api_key' => 'xxxxxx',            'api_name' => 'X-API-KEY',            'http_user' => 'admin',            'http_pass' => 'xxxxx',            'http_auth' => 'basic',        );        $this->rest->initialize($config);// Set method of sending data        $method = 'post';// create your param data        $param = array(            'id' => $this->input->post('id'), // works fine here            'name' => $this->input->post('name')        );// url where you want to send your param data.        $uri = 'employer/postNewProject';        // set format you sending data        $this->rest->format('application/json');// send your param data to given url using this        $result = $this->rest->{$method}($uri, $params);

//code for your controller employer/postNewProject

Controller

function postNewProject(){    $data=array(        'id' => $this->post('id'),        'name' => $this->post('name')        );      print_r($data);}


i figure out when and empty 3rd perameter is passed(or when you remove 3rd param) then it works.

    //Not working    $user = $this->rest->post('employer/postNewProject', $param, 'json');    //when i change to this ,it's working     $user = $this->rest->post('employer/postNewProject', $param.'');     //or     $user = $this->rest->post('employer/postNewProject', $param);

if some one has a better solution so that i can award bounty.


make sure you receive data, use

 echo '<pre> all data received: '.print_r($_REQUEST,1).'</pre>';

make sure is from post

echo '<pre> post data: '.print_r($_POST,1).'</pre>';