Laravel CSRF 保护异常现在工作

我的 Laravel 项目在此链接中


http://localhost/demo/public // laravel project

我有这个外部 HTML 表单


http://localhost/attendance

现在我想将数据从表单发送到 Laravel,但出现此错误


419页面已过期


所以在我的 Laravel 项目 VerifyCsrfToken 类中我写了这个


class VerifyCsrfToken extends Middleware

{

    /**

     * The URIs that should be excluded from CSRF verification.

     *

     * @var array

     */

    protected $except = [

        'http://localhost/attendance'

    ];

}

但仍然得到同样的错误


419页面已过期


守着星空守着你
浏览 143回答 2
2回答

隔江千里

Laravel 为您解析应用程序的 baseUrl,无需放置完整路径,在您的情况下,中间件应如下所示:class VerifyCsrfToken extends Middleware{    /**     * The URIs that should be excluded from CSRF verification.     *     * @var array     */    protected $except = [        'attendance/*'    ];}

慕尼黑的夜晚无繁华

一种解决方案是将数据作为 GET 请求而不是 POST 请求发送。一旦您将您的工作放到网上,您将面临浏览器上的跨站点保护。在URI要排除的是一个接收的请求,以便http://localhost/demo/public
打开App,查看更多内容
随时随地看视频慕课网APP