3

我正在使用codeigniter 休息服务器 api 库。

当我输入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
        }
    }
4

2 回答 2

1

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

第一步:

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

必须更改为:

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

第二步:

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

于 2015-06-11T10:08:34.037 回答
0

这个问题很老,但对于那些发现这个问题的人来说,答案是:

https://github.com/chriskacerguis/codeigniter-restserver使用 PUT 方法时,API KEY 应在 put 标头变量中为 x-www-form-urlencoded 类型。

使用谷歌浏览器邮递员并填写如下图: 在此处输入图像描述

于 2018-01-28T13:26:14.267 回答