我正在使用Phil Sturgeon的codeigniter restserver,
https://github.com/chriskacerguis/codeigniter-restserver
我遇到了一个问题:
当我发出请求时,一切正常,但当我发布时,我得到了“500内部服务器错误”
<div id="container">
<h1>An Error Was Encountered</h1>
<p>The action you have requested is not allowed.</p>
</div>
我的代码如下:
function test_post()
{
$this->response('ok', 200); // 200 being the HTTP response code
}
function test_get()
{
$this->response('ok', 200); // 200 being the HTTP response code
}
可在以下URL中找到工作的GET handelling
https://manage.pineconetassel.com/index.php/api/example/test/
注意,我只允许https。
我用过投掷。它需要测试POST方法,但它不起作用。
这是剩下的。php配置:
$config['force_https'] = TRUE;
$config['rest_default_format'] = 'json';
$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'] = 'ldap';
$config['auth_library_class'] = '';
$config['auth_library_function'] = '';
$config['rest_valid_logins'] = array('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'] = FALSE;
$config['rest_key_column'] = 'key';
$config['rest_key_length'] = 40;
$config['rest_key_name'] = 'X-API-KEY';
$config['rest_logs_table'] = 'logs';
$config['rest_enable_logging'] = FALSE;
$config['rest_access_table'] = 'access';
$config['rest_enable_access'] = FALSE;
$config['rest_logs_json_params'] = FALSE;
$config['rest_limits_table'] = 'limits';
$config['rest_enable_limits'] = FALSE;
$config['rest_ignore_http_accept'] = FALSE;
$config['rest_ajax_only'] = FALSE;
我是否做错了什么,或者使用了错误的方法来测试帖子,或者我需要配置一些东西?
设置$config['csrf\u protection']=FALSE代码>在
config/config中。php
注意它不是uderconfig/rest。php
公认的答案是正确的。但是如果您不想禁用$config['csrf\u protection']
以防web表单需要它,则需要排除REST API URI,例如,您的REST url以/API/
开头,只需设置
$config['csrf_exclude_uris'] = array(
'api/[a-z0-9/_-]+'
);
它也在config/config.php
下。我使用正则表达式来简化它。