Ho passato tutta la giornata a cercare di capire questo problema. Pubblicare questo problema qui è la mia ultima speranza. Spero che qualcuno possa aiutare a continuare a lavorare sul mio primo lavoro.CodeIgniter Passaggio dei dati POST da RestClient a RestServer API
Quindi, POST funziona correttamente quando si passa direttamente i dati dalle mie viste al RestServer direttamente. Tuttavia, l'API RESTServer non è in grado di trovare i dati POST inviati dal RestClient.
Qui ci sono i frammenti:
RestClient API:
$ver = 'v1';
$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);
$this->rest->format('application/json');
$param = array(
'id' => $this->input->post('id'), // works fine here
'name' => $this->input->post('name')
);
$user = $this->rest->post('employer/postNewProject', $param, 'json');
//if (isset($user->errors)) show_404('admin');
$this->rest->debug();
RestServer API
class Employer extends REST_Controller
{
public function __construct()
{
parent::__construct();
$this->lang->load("application");
$this->load->library("users/auth");
Datamapper::add_model_path(array(APPPATH."modules"));
}
public function postNewProject_post()
{
// I tired $this->post() and $this->input->post() but both not finding the data
$message = array("id" => $this->post("id"), "name" => $this->input->post("name"));
$this->response($message, 200); // 200 being the HTTP response code
}
}
risultati:
Response when using $this->post('id');
{"id":false}
Response when using $this->post();
{"id":[]}
Nota: Ho sostituito i posti richieste con i dati hardcoded, e ancora il RestServer non è in grado di ricevere i dati dal mio RestClient.
Se avete bisogno di me per fornire qualcos'altro, per favore chiedete.
Grazie in anticipo.
Provare con il formato impostato con solo json come '$ this-> rest-> format ('json');' – jagad89