我正在开发一个使用CakePHP 3框架的API。现在,我正在从POSTMAN客户端发送GET请求。用户将在标头中传递一个API密钥。 cakephp3-无法在控制器中获取授权标头
我想在我的控制器功能中获取这个头文件。
这是我的控制器看起来像
namespace Api\Controller;
use Cake\Auth\DefaultPasswordHasher;
use Api\Controller\AppController;
use Cake\Cache\Cache;
use Cake\Http\ServerRequest;
class ApiController extends AppController
{
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
}
public function myinfo()
{
if($this->request->is('get')) {
$key = $this->request->getHeaderLine('Authorization');
$this->set('key', $key);
}
$this->set('_serialize', ['key']);
}
}
是我得到的错误是:HeaderLine is not a function
我也尝试了一些更多的选择:
$acceptHeader = $this->request->getHeader('Authorization');
但这也扔类似的错误。标题不是一个功能。
参考:Link
CakePHP的版本:3.3.5
请总是提到你的_exact_ CakePHP的版本(最后一行'供应商/ cakephp中/ cakephp/VERSION.txt') - 谢谢! – ndm
Cakephp 3.3。5 @ndm –
然后,您可能需要仔细查看链接文档中的最后一个示例。 – ndm