cakephp 4 针对特定操作禁用 csrf

时间:2021-06-01 19:44:34

标签: ajax http-post csrf cakephp-4.x

我正在研究 cakephp4 项目
希望允许一个动作从没有 csrf 的任何客户端获取 post 请求。
根据 documentation,我编写了以下代码,但在发布请求时显示 BAD REQUEST。

class MylogsController extends AppController
{

  public function initialize(): void
  {
      parent::initialize(); 
      $this->loadComponent('Security');
  }

  public function beforeFilter(EventInterface $event)
  {
      parent::beforeFilter($event);
      $this->Security->setConfig('unlockedActions', ['add']);
  }

  public function add()
  {
    debug($this->request->getData());exit;
  }
}

0 个答案:

没有答案
相关问题