简体   繁体   中英

CodeIgniter Rest_Controller: Invalid API Key

I'm learning to use codeigniter and in general to create the API.

I have installed REST_Controller in my project, I have created in my db the table 'logs' and 'keys' using the query that I found in the Rest.php file.

Now If I do a get, the method works. But if I tried to do a post (from Postman) I receive this error:

"status": false,
"error": "Invalid API Key "

I have done a post to link: localhost/..../controllername/create (so without using create_post) and I pass values using body/form-data in Postman.

If I see the data inside the 'logs' table, i can see the post with the values that I have passed, but I have no values about the api_key parameter, while the 'keys' table is completely empty.

How can I do to resolve this error?

Go to config/rest.php and set the API KEY name you wil send, default is:

$config['rest_key_name'] = 'X-API-KEY';

You can change for any other like: token, authtoken, etc. If you are using tools like Postman try send in the headers: name: X-API-KEY value: your_token_value

If you are using postman, you need to set Authorization to basic and pass following values, which is default you should change it in your config/rest.php file. Also you can set your API keys for different users in your db table. Please study the rest_controller files on github .

username = 'admin'
password = '1234'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM