php - 使用 RestServer 的 Api key 无效

标签 php codeigniter codeigniter-restserver

我正在使用 the codeigniter rest server api library.

当我输入 http://localhost/projects/myapi/key/index_put.php然后按回车键给我以下错误:

<xml>
<status>0</status>
<error>Invalid API Key</error>
</xml>

当我在 url 中给出一个虚拟字符串时,例如:

http://localhost/projects/myapi/key/index_put.php?X-API-KEY=asldfj9alsdjflja97979797997

我遇到了同样的问题。有什么想法吗?

index_put.php:

public function index_put() {
        // Build a new key
        $key = self::_generate_key();
        // If no key level provided, give them a rubbish one
        $level = $this->put('level') ? $this->put('level') : 1;
        $ignore_limits = $this->put('ignore_limits') ? $this->put('ignore_limits') : 1;

        // Insert the new key
        if (self::_insert_key($key, array('level' => $level, 'ignore_limits' => $ignore_limits))) {
            $this->response(array('status' => 1, 'key' => $key), 201); // 201 = Created
        } else {
            $this->response(array('status' => 0, 'error' => 'Could not save the key.'), 500); // 500 = Internal Server Error
        }
    }

最佳答案

我遇到了同样的问题。不要在 URL 中提及 put/get/post,RestServer 本身根据您传递的参数识别请求性质,需要两步来解决您的问题。

1st Step :

http://localhost/projects/myapi/key/index_put.php

必须更改为:

http://localhost/projects/myapi/key/index.php

2nd step:

在键表中使用 sha1(最多 40 个字符)创建一个 api kay(表结构显示在 config/rest.php 文件中), 在 is_private_key 字段中输入 1,在 ip_address 字段中输入::1。 创建记录,并再次检查。

关于php - 使用 RestServer 的 Api key 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30713327/

相关文章:

php - UPLOAD_ERR_CANT_WRITE 但其他文件正在上传

php - 一次引用两个php文件

codeigniter - 飞行前响应中的 Access-Control-Allow-Headers 不允许 Angular 2 请求 header 字段授权

php - Codeigniter 3 自动加载 Controller

php - 通知 : Undefined property: stdClass error on front end

php - Join 不能与 WHERE 一起正常工作

php - 如何将 CSS 添加到 CodeIgniter View 中的 foreach 结果?

php - CodeIgniter form_validation 中的 regex_match 生成 : Message: preg_match(): No ending delimiter '/' found

php - codeIgniter 使用 mysql_real_escape_string() 代替。数据库连接问题