1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【cakephp3】CSRFコンポーネントロード時のテストコードのリクエストの送り方

1
Posted at

バージョン

Cakephp3 3.5

背景

$this->loadComponent('Csrf')で
CSRFコンポーネントをロードしているコントローラにて
テストコードを書いた際、$this->postが403Forbiddenになり困った。

解決

$this->_csrfToken = true; //この行を追加

$this->get('users/add');

$email = 'test@email.com';
$button = 'confirm';

$this->session($this->_requestSession->read());
$this->post('users/add',compact(['email','button']);

※1行目が無いと403Forbiddenがレスポンスされる。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?