gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 00:50:08 29 4
gpt4 key购买 nike

我正在使用 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com