我正在開發一個使用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