代码点火器休息服务器 POST "not allowed" ,但 GET 工作正常



我正在使用的Phil Sturgeon的代码点火器restserver

https://github.com/chriskacerguis/codeigniter-restserver

我遇到了一个问题:

当我执行PUT请求时,一切都正常,但当我执行POST时,我得到了"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移交

https://manage.pineconetassel.com/index.php/api/example/test/

注意,我只允许https。

我使用了hurl.it来测试POST方法,但它不起作用。

这是rest.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;

我是否做错了什么或使用了错误的方式来测试POST,或者我需要配置一些东西?

config/config.php 中设置$config['csrf_protection'] = FALSE;

请注意,它不是uder config/rest.php

接受的答案是正确的。但是,如果您不想禁用$config['csrf_protection'],以防web表单需要它,您需要排除REST API URI,例如,您的REST url以/api/开头,只需设置

$config['csrf_exclude_uris'] = array(
   'api/[a-z0-9/_-]+'
);

它也在config/config.php之下。我使用正则表达式来使它变得简单。

最新更新