3
2

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.7 へajaxでPOSTを行うと403エラーになる

Posted at

CSRF機能が有効になっていることが原因でしたので、とりあえず無効での対応です。

cakephp3系でajax通信をしたいけど403エラーで失敗する、、
https://teratail.com/questions/158625

同じ内容であったのですが、3.6はsrc/Application.phpにあった設定が、
3.7ではrouters.phpになっていました。

routers.php
 // Register scoped middleware for in scopes.
   $routes->registerMiddleware('csrf', new CsrfProtectionMiddleware([
        'httpOnly' => true
    ]));
    /**
     * Apply a middleware to the current route scope.
     * Requires middleware to be registered via `Application::routes()` with `registerMiddleware()`
     */
    $routes->applyMiddleware('csrf');

routers.php
 // Register scoped middleware for in scopes.
 /*  $routes->registerMiddleware('csrf', new CsrfProtectionMiddleware([
        'httpOnly' => true
    ])); */
    /**
     * Apply a middleware to the current route scope.
     * Requires middleware to be registered via `Application::routes()` with `registerMiddleware()`
     */
   // $routes->applyMiddleware('csrf');
3
2
1

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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?