duanjianshen4871 2018-09-20 18:29 采纳率: 100%
浏览 64

405方法不允许 - CodeIgniter Rest-server

I am having troubles with Codeigniter - Rest Server for a week already. I have a controller called Users with 2 methods all_users_get and register_post.

  1. all_users_get is working fine.
  2. register_post

    returns { "status": false, "error": "Unknown method" }

If I change the method all_users_get for POST I get the same error, just works with GET

<?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 Users extends REST_Controller {

function __construct()
{
    // Construct the parent class
    parent::__construct();

    $this->load->model('user_model');

    // Configure limits on our controller methods
    // Ensure you have created the 'limits' table and enabled 'limits' within application/config/rest.php
    $this->methods['users_get']['limit'] = 500; // 500 requests per hour per user/key
    $this->methods['users_post']['limit'] = 100; // 100 requests per hour per user/key
    $this->methods['users_delete']['limit'] = 50; // 50 requests per hour per user/key
}

/**
 * @method: GET
 * Fetch all users
 */

public function all_users_get()
{
    $users = $this->user_model->all_users();
    // Check if the users data store contains users (in case the database result returns NULL)
    if ($users)
    {
        // Set the response and exit
        $this->response($users, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
    }
    else
    {
        // Set the response and exit
        $this->response([
            'status' => FALSE,
            'message' => 'No users were found'
        ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
    }
    $this->response($users, REST_Controller::HTTP_OK);

}

/**
 * User Register
 * *************************
 * 
 * @param: fullname
 * @param: email address
 * @param: password
 * @param: username
 * 
 * *************************
 * @method: POST
 * @link : api/users/register
 */

public function resgister_post()
{

    header('Access-Control-Allow-Origin: *');

    $this->response("Teste", REST_Controller::HTTP_OK);

}

}

I am running my code in localhost with Xampp and I found on phpinfo

_SERVER["REQUEST_METHOD"] GET

I am confused I don't know if this had something to do with Xampp conf or my code, please help. Thank you all

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改
    • ¥20 wireshark抓不到vlan
    • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
    • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持