[英]Error from codeigniter restful api
I am using Phil Sturgeon's Rest Server and Rest Client to buid codeigniter restful api. 我正在使用Phil Sturgeon的Rest Server和Rest Client来使codeigniter restful api生效。 however I am encountering the following error message: 但是我遇到以下错误消息:
============================================= REST Test ============================================ REST测试
============================================= Request ============================================
Response 响应
A PHP Error was encountered 遇到PHP错误Severity: Notice 严重程度:注意
Message: Undefined index: base64 消息:未定义的索引:base64
Filename: libraries/REST_Controller.php 文件名:libraries / REST_Controller.php
Line Number: 1866 行号:1866
Backtrace: 回溯:
File: D:\\xampp\\htdocs\\MB\\application\\libraries\\REST_Controller.php 文件:D:\\ xampp \\ htdocs \\ MB \\ application \\ libraries \\ REST_Controller.phpCall details 通话详情
Provide a http header when accessing API Link 访问API链接时提供http标头
Authorization: Basic YWRtaW46MTExMQ==
YWRtaW46MTExMQ==
is the passphrase encoded in base64 YWRtaW46MTExMQ==
是以base64编码的密码短语
if decoded it is 如果解码的话
admin:1111
admin
is your username 1111
is your password admin
是您的用户名1111
是您的密码
Website to encode decode base https://www.base64encode.org/ 网站编码解码基础https://www.base64encode.org/
You can use postman https://www.getpostman.com/ to provide Authorization header or 您可以使用邮递员https://www.getpostman.com/提供授权标头,或
When accessing link on browser you can fill the alert box with username and password 在浏览器上访问链接时,您可以在警报框中填写用户名和密码
You can find your username and password at application/config/rest.php
您可以在application/config/rest.php
找到您的用户名和密码
find a config of $config[rest_valid_logins]=
查找$config[rest_valid_logins]=
If you want to disable authentication; 如果要禁用身份验证; it's simple: goto config/rest.php Change; 很简单:goto config / rest.php更改; $config['rest_auth'] = 'basic'; $ config ['rest_auth'] ='基本'; to $config['rest_auth'] = ''; 为$ config ['rest_auth'] =''; Else, in header of your API request you have to send AUTH credential listed in: $config['rest_valid_logins'] = array('admin' => '1234'); 否则,在您的API请求的标头中,您必须发送以下列表中列出的AUTH凭证:$ config ['rest_valid_logins'] = array('admin'=>'1234');
NOTE:If you facing problem, you should change your .htaccess as following: 注意:如果遇到问题,应按以下步骤更改.htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
#RewriteRule ^(.*)$ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#RewriteRule ^(.*)$ - [E=REMOTE_USER:%{HTTP:Authorization},L]
#RewriteCond %{HTTP:Authorization} ^(.*)
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^([a-z0-9_-]+)\.html$ index.php/page/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|asset|robots\.txt)
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
</IfModule>
If you still has problem, change code of libraries\\REST_Controller.php 如果仍然有问题,请更改library \\ REST_Controller.php的代码
Find this in your code: 在您的代码中找到这个:
elseif ($this->input->server('HTTP_AUTHENTICATION'))
{
if (strpos(strtolower($this->input->server('HTTP_AUTHENTICATION')), 'basic') === 0)
{
list($username, $password) = explode(':', base64_decode(substr($this->input->server('HTTP_AUTHORIZATION'), 6)));
}
}
and replace with: 并替换为:
elseif ( $this->input->server('HTTP_AUTHENTICATION') || $this->input->server('REDIRECT_REMOTE_USER') || $this->input->server('REDIRECT_HTTP_AUTHORIZATION') )
{
$HTTP_SERVER_AUTH = ($this->input->server('HTTP_AUTHENTICATION')) ? $this->input->server('HTTP_AUTHENTICATION') : $this->input->server('REDIRECT_HTTP_AUTHORIZATION');
if(!$HTTP_SERVER_AUTH)
{
$HTTP_SERVER_AUTH = $this->input->server('REDIRECT_REMOTE_USER');
}
if (strpos(strtolower($HTTP_SERVER_AUTH),'basic') === 0)
{
list($username,$password) = explode(':',base64_decode(substr($HTTP_SERVER_AUTH, 6)));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.