codeigniter 3 rest api with angular 5 post method raise error 405 method not allowed |
codeigniter 3 rest api with angular 5 post method raise error 405 method not allowed. Please suggest
That's hard to say without knowing your code/setup.
When in doubt, test one thing at a time, start with your API with postman (https://www.getpostman.com/) and see if you can replicate the issue.
(10-24-2018, 11:52 PM)ragingTorch Wrote: That's hard to say without knowing your code/setup. Hi, it's working from postman but it's not working from angular post request.I added my rest, other php page. controller code <?php use Restserver\Libraries\REST_Controller; defined('BASEPATH') OR exit('No direct script access allowed'); require APPPATH . 'libraries/REST_Controller.php'; require APPPATH . 'libraries/Format.php'; class Api extends REST_Controller { function __construct(){ parent::__construct(); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Headers: X-Requested-With'); header('Content-Type: application/json'); $this->load->model('Apimodel','apimodel'); $this->load->model('Adminmodel','adminmodel'); $this->load->model('Usermodel','usermodel'); $this->load->model('Blogmodel','blogmodel'); $this->load->model('Companymodel','companymodel'); $this->load->library('pagination'); //$this->load->model('Settingsmodel','settingsmodel'); } public function userLogin_post(){ $data = []; $data['email'] = $this->post('email'); $data['password'] = $this->post('password'); $result = $this->usermodel->userLogin($data); //pre($result,1); if ($result['status']) { $this->setResponse(REST_Controller::HTTP_CREATED,TRUE, $result['message'],'create'); // OK (200) being the HTTP response code } else { $this->setResponse(REST_Controller::HTTP_INTERNAL_SERVER_ERROR,$result['status'],$result['message']); } } and this code in routes page $route['api/userlogin'] = 'api/userLogin'; I am trying to login using credentials by post method from angular 5
I did project with angularJS and CI3 Restful api about 2 years ago.
There was a prefix that you need to add to json response: PHP Code: public function random_cars_get() I don't know is that is case in Angular 5
Also you controller method name structure should be as follows:
If doing POST request 1. your URL is controllername/user 2. your controller method name is public function user_post(){} If doing GET request 1. your URL is controllername/user 2. your controller method name is public function user_get(){} If doing DELETE request 1. your URL is controllername/user 2. your controller method name is public function user_delete(){} and so on. These informations should be in documentation of CI rest api
(10-25-2018, 12:09 AM)neuron Wrote: Also you controller method name structure should be as follows: I already done this and i have posted the code in 2nd thread.Please check and i also added my issue screenshot.
In your screenshot I see that your request method is OPTIONS.
as your method name is userLogin_post your request method should be POST request. Also first try without setting routing. I mean rename your method userLogin_post to login_post and do POST request to your-domain/api/login |
Welcome Guest, Not a member yet? Register Sign In |