Я потратил весь свой день, пытаясь понять эту проблему. Опубликовать эту проблему здесь - моя последняя надежда. Надеюсь, кто-то может помочь продолжить работу над моей первой работой.
Итак, POST отлично работает, когда напрямую передаются данные из моих представлений на RestServer напрямую. Однако API RESTServer не может найти данные POST, отправленные из RestClient.
Вот фрагменты:
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
}
}
Результаты:
Response when using $this->post('id');
{"id":false}
Response when using $this->post();
{"id":[]}
Примечание. Я заменил POSTS-запросы жестко запрограммированными данными, и, тем не менее, RestServer не сможет получить данные из моего RestClient.
Если вам нужно, чтобы я предоставил что-нибудь еще, спросите.
Спасибо заранее.