php - codeigniter rest server POST "not allowed",但 GET 工作正常

标签 php codeigniter rest

我正在使用 Phil Sturgeon 的 codeigniter-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;

注意它不是 config/rest.php

关于php - codeigniter rest server POST "not allowed",但 GET 工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28773285/

相关文章:

php - Codeigniter 2.1 - 网站管理部分的安全

php - Codeigniter 视频上传不起作用

php - Backbone 模型保存状态

javascript - 单击 html 按钮运行 PHP 函数

php - 如何同步同一台机器上不同MySQL数据库的两个表?

php - 是否可以使用 PHP 解释器代替 JavaScript v8 来实现 Node.js?

基于标准 WCF 服务的 RESTful WCF 服务

mysql - 使用Spring框架发送POST请求

具有默认值的 PHP 赋值

php - laravel 在循环中附加 wheres 以执行 AND 过滤