私は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']);
}
}
どのように見えるか
は、これは私が得ているエラーは、次のとおりです。
$acceptHeader = $this->request->getHeader('Authorization');
が、これも投げた:HeaderLine is not a function
は、私はまた、いくつかのより多くのオプションを試してみました同様のエラー。ヘッダーは関数ではありません。
参考:Link
CakePHPのバージョン:3.3.5
常にあなた_exact_ CakePHPのバージョン(最後の行は、 'ベンダー/ cakephpのに言及してください/ cakephp/VERSION.txt') - ありがとう! – ndm
Cakephp 3.3。5 @ndm –
次に、リンクされたドキュメントの最後の例を詳しく見ることができます。 – ndm