dtxb75622 2015-06-08 15:31
浏览 133
已采纳

使用RestServer的Api密钥无效

I am using the codeigniter rest server api library.

When I enter http://localhost/projects/myapi/key/index_put.php and hit enter gives me the following error:

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

When I give a dummy string in the url, like:

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

I get the same problem. Any idea?

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
        }
    }
  • 写回答

2条回答 默认 最新

  • doumei1955 2015-06-11 10:08
    关注

    i faced the same issue .don't mention put/get/post in URL ,RestServer itself recognizes the request nature base on parameter you pass two step required to solve your problem .

    1st Step :

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

    must change to :

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

    2nd step:

    create an api kay using sha1(max 40 character) in the keys table (table structure show in config/rest.php file), enter 1 in is_private_key field and ::1 in ip_address field. create the record ,and check it again .

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?