【发布时间】:2018-07-24 17:00:34
【问题描述】:
我正在尝试从我的 ionic 应用程序中发布注册表单数据。我使用 ionic 3 和 Codeigniter Rest Api 作为后端。
Codeigniter 休息 API: Codeigniter Rest Server
这是我的ionic post函数
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);
});
})
}
这是我的codeigniter post功能
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 发送请求,并且它有效。
有什么解决方案/建议吗?
谢谢。
【问题讨论】:
标签: angular codeigniter http-post ionic3