【发布时间】:2014-09-01 04:06:18
【问题描述】:
我花了一整天的时间来解决这个问题。在这里发布这个问题是我最后的希望。我希望有人可以帮助我继续从事我的第一份工作。
所以,当直接将数据从我的视图直接传递到 RestServer 时,POST 可以正常工作。但是,RESTServer API 无法找到从 RestClient 发送的 POST 数据。
这里是sn-ps:
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 接收数据。
如果您需要我提供其他任何东西,请询问。
提前谢谢你。
【问题讨论】:
-
尝试使用只有 json 的 set 格式,例如
$this->rest->format('json');
标签: php codeigniter codeigniter-2 rest-client codeigniter-restserver