Welcome Guest, Not a member yet? Register   Sign In
codeigniter 3 rest api with angular 5 post method raise error 405 method not allowed
#3
Wink 
(This post was last modified: 10-25-2018, 12:11 AM by rupamhazra.)

(10-24-2018, 11:52 PM)ragingTorch Wrote: 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.

 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

Attached Files Thumbnail(s)
   

.php   config.php (Size: 18.63 KB / Downloads: 118)
.php   REST_Controller.php (Size: 80.93 KB / Downloads: 119)
.php   rest.php (Size: 20.88 KB / Downloads: 124)
Reply


Messages In This Thread
RE: codeigniter 3 rest api with angular 5 post method raise error 405 method not allowed - by rupamhazra - 10-25-2018, 12:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB