philsturgeon’s REST Api codeigniter Always returni

2019-07-04 11:26发布

I am always getting the this error.

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

But all syntax are correct from my side. because everything is working fine on the browser but same URL integration on the devices gives the 'unknown method error' . I am using this 'get' method. Sample URL

       SITEURL/api/login/test?req_type=custom

Does I am missing something while integrating? any setting anything.. I have just included the library and rest config file yet. and working Please help asap. Thank you in advance.

3条回答
神经病院院长
2楼-- · 2019-07-04 11:48

You also need to check that from device which method your are getting means they are sending 'POST' or 'GET' so you can update your function name accordingly.

In my case I have done the function name as _get to the methods but from device methods of sending parameter is 'POST' which I am trying to access as 'GET'.

So please cross check this once. :) Hope this help anyone.

查看更多
闹够了就滚
3楼-- · 2019-07-04 11:49

I think your problem is the name of controller is the same with the name of method try to make a test:

if the name of your controller is:

class Test extends REST_Controller{
    //your method name is different from the name of controller class
    public function testget_get(){ 
        echo $this->response(array('test'=> 'test'), 200);
    }
}

I have experienced this problem on hmvc structure.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-07-04 12:00

When you create a method with the library, you need to append the type of request you are going to make to it.

So, if your method is test, and you are making a GET request to it, it needs to look like this:

function test_get(){
    ...
}

Same with POST requests

function test_post(){
    ...
}

Same with PUT, and DELETE as well.

NB This is only a guess since you didn't include any of your code for some reason.

查看更多
登录 后发表回答