我正在尝试从我的离子型应用程序中发布注册表单数据。我使用离子3和Codeigniter Rest作为后端。
Codeigniter Rest Api:代码点火器Rest服务器
这是我的离子后函数
postAuthData(data:any){
let headers = new Headers();
headers.append('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
return new Promise((resolve,reject)=>{
this.http.post("http://localhost/giftinrest/index.php/api/example/users", data,{headers:headers})
.subscribe(res => {
resolve(res.json());
}, (error) => {
reject(error);
});
})
}这是我的代码点火器发布函数
public function users_post()
{
$message = [
'id' => 100, // Automatically generated by the model
'name' => $this->post('name'),
'email' => $this->post('email'),
'message' => 'Added a resource'
];
$this->set_response($message, REST_Controller::HTTP_CREATED); // CREATED (201) being the HTTP response code
}我得到的$this->post('email')为空。
我试着改变标题,但没有起作用。
我试着将邮递员的帖子请求发送给http://localhost/giftinrest/index.php/api/example/users,结果成功了。
是否有任何解决方案/建议?
谢谢。
发布于 2018-07-27 12:40:50
在CI中,要获取post数据,您可以这样做:
$this->input->post();https://stackoverflow.com/questions/48781809
复制相似问题