philsturgeon’s REST Api codeigniter Always returning: status:0, error:Unknown method

冷暖自知 提交于 2019-12-10 17:35:53

问题


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.


回答1:


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.




回答2:


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:


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.



来源:https://stackoverflow.com/questions/19517714/philsturgeon-s-rest-api-codeigniter-always-returning-status0-errorunknown-me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!