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

查看:74
本文介绍了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天全站免登陆