我遇到了从CodeIgniter中的Restful API获取响应的问题。这是我的控制器
public function user_post() {
if(!empty($userData['name']) && !empty($userData['email']) &&
!empty($userData['gender']) && !empty($userData['age']) &&
!empty($userData['phone']) && !empty($userData['password'])){
//insert user data
$uuid = uniqid('', true);
$now = date('Y-m-d H:i:s');
$enc_password = md5($this->input->post('password'));
$insert = $this->auth_model->insert( $uuid, $enc_password,$now);
//check if the user data inserted
if(!$insert){
//set the response and exit
$this->response([
"status" => TRUE,
"message" => "User has been added successfully."
], REST_Controller::HTTP_OK);
}else{
//set the response and exit
$this->response("Some problems occurred, please try again.",
REST_Controller::HTTP_BAD_REQUEST);
}
}else{
//set the response and exit
$this->response("Provide complete user information to create.",
REST_Controller::HTTP_BAD_REQUEST);
}
}
请帮助,如果你有任何解决方案..
答案 0 :(得分:0)
您的请求应
import {Injectable} from '@angular/core';
import {Http, Response, Headers, RequestOptions} from '@angular/http';
import {Observable} from 'rxjs';
import {Module} from '../checkboxes/checkboxes';
@Injectable()
export class moduleService {
handleError: any;
private moduleUrl = '/api/lodmodule';
constructor(private http: Http) {}
createModule(id: number) {
let head = new Headers({'Content-Type': 'application/json'});
this.http.post(this.moduleUrl, id, {headers: head}).map(response => response.json())
.subscribe(
() => {console.log(id)}
);
}
}
由于您使用url: 'https://yoursite.com/api/v1/user'
method: 'post'
而不是REST_Controller
更改强>
CI_Controller
进入
$this->input->post('password')
这与其他HTTP请求相同
$this->post('password')