简体   繁体   English

CodeIgniter Rest服务器集成

[英]CodeIgniter Rest Server Integration

I have downloaded CodeIgniter Rest Server source code from github https://github.com/chriskacerguis/codeigniter-restserver . 我已经从github https://github.com/chriskacerguis/codeigniter-restserver下载了CodeIgniter Rest Server源代码。

I have integrated as per readme document but i am getting an error of "Invalid API Key " with 403 Forbidden error when i call like htttp://www.sitename.com:81/api/key/index to generate first time new key and store into database. 我已经按照自述文件进行了集成,但是当我像htttp://www.sitename.com:81 / api / key / index这样生成第一次新密钥时,却收到了“ Invalid API Key”和403 Forbidden错误的错误并存储到数据库中。

Screenshot 1 : See this screenshot of error occured in FF browser as well as in POSTMAN Extension used in Google Chrome Windows 7 - 64bit 屏幕截图1: 查看此屏幕截图,该屏幕截图显示了FF浏览器以及Google Chrome Windows 7-64bit中使用的POSTMAN Extension中发生的错误

Below is the code in my Rest.php >>>>> 以下是我的Rest.php中的代码>>>>>

<?php 
defined('BASEPATH') OR exit('No direct script access allowed');
$config['force_https'] = FALSE;
$config['rest_default_format'] = 'json';
$config['rest_supported_formats'] = ['json','array','csv','html','jsonp','php','serialized','xml'];
$config['rest_status_field_name'] = 'status';
$config['rest_message_field_name'] = 'error';
$config['enable_emulate_request'] = TRUE;
$config['rest_realm'] = 'REST API';
$config['rest_auth'] = FALSE;
$config['auth_source'] = ''; //i set it as none/blank, default value set as 'ldap'
$config['auth_library_class'] = '';
$config['auth_library_function'] = '';
$config['rest_valid_logins'] = ['admin' => '1234'];
$config['rest_ip_whitelist_enabled'] = FALSE;
$config['rest_ip_whitelist'] = '';
$config['rest_ip_blacklist_enabled'] = FALSE;
$config['rest_ip_blacklist'] = '';
$config['rest_database_group'] = 'default';
$config['rest_keys_table'] = 'keys';
$config['rest_enable_keys'] = TRUE; //i set it as TRUE default value is FALSE
$config['rest_key_column'] = 'key';
$config['rest_limits_method'] = 'ROUTED_URL';
$config['rest_key_length'] = 40;
$config['rest_key_name'] = 'X-API-KEY';
$config['rest_enable_logging'] = TRUE;//i set it as TRUE default value is FALSE
$config['rest_logs_table'] = 'logs';
$config['rest_enable_access'] = FALSE;
$config['rest_access_table'] = 'access';
$config['rest_logs_json_params'] = FALSE;
$config['rest_enable_limits'] = FALSE;
$config['rest_limits_table'] = 'limits';
$config['rest_ignore_http_accept'] = FALSE;
$config['rest_ajax_only'] = FALSE;
$config['rest_language'] = 'english';

Code in routes.php >> route.php中的代码>>

$route['api/key/index'] = 'api/key/index'; // Generate First Time Key

Can anyone please guide me how to generate this first time key for CI rest server? 谁能指导我如何为CI Rest Server生成此首次密钥?

It will be really helpful if anyone give solution for this issue asap as i was trying to resolve it since 2 days to find the solution but did not get any success. 如果有人尽早为这个问题提供解决方案,那将是非常有用的,因为自2天以来我一直试图解决它,但是找到了解决方案,但是没有成功。 :( :(

From that library's repo documentation: 从该库的回购文档中:

//By default, the HTTP will be X-API-KEY. This can be configured in config/rest.php.
$ curl -X POST -H "X-API-KEY: some_key_here" http://example.com/books

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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