laravel 5.5 由于不活动,页面已过期.请刷新并重试 [英] laravel 5.5 The page has expired due to inactivity. Please refresh and try again

查看:37
本文介绍了laravel 5.5 由于不活动,页面已过期.请刷新并重试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Laravel 的新手,我有一个我不明白的问题.我的项目中有一个日志表单,我的方法是 POST.当我尝试请求时,结果是:

I'm new with Laravel and I have a problem which I don't understand. I have а log form in my project and my method is POST. When I try a request the result is:

'由于不活动,页面已过期.请刷新并尝试再次.'

'The page has expired due to inactivity. Please refresh and try again.'

但是如果我将方法更改为 GET,它就可以正常工作.

But if I change the method to GET, It works fine.

谁能告诉我这是为什么以及如何解决?因为我当然需要 POST 方法.

Can someone tell me why is that and how to fix it? because of course I need POST method.

推荐答案

此问题来自CSRF令牌验证失败.所以要么你没有发布一个,要么你发布了一个不正确的.

This problem comes from the CSRF token verification which fails. So either you're not posting one or you're posting an incorrect one.

它适用于 GET 的原因是,对于 Laravel 中的 GET 路由,没有发布 CSRF 令牌.

The reason it works for GET is that for a GET route in Laravel, there is no CSRF token posted.

您可以通过调用以下方式在表单中发布 CSRF 令牌:

You can either post a CSRF token in your form by calling:

{{ csrf_field() }}

或者在 app/Http/Middleware/VerifyCsrfToken.php 中排除你的路由(不推荐):

Or exclude your route (NOT RECOMMENDED DUE TO SECURITY) in app/Http/Middleware/VerifyCsrfToken.php:

protected $except = [
    'your/route'
];

这篇关于laravel 5.5 由于不活动,页面已过期.请刷新并重试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆