使用Laravel提交POST请求出现The page has expired due to inactivity. Please refresh and try again.

问题:

提交POST请求,出现如下错误:

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

这是由于在Laravel框架中有此要求:

任何指向 web 中 POST, PUT 或 DELETE 路由的 HTML 表单请求都应该包含一个 CSRF 令牌(CSRF token),否则,这个请求将会被拒绝。

解决办法1: 加上 CSRF token

<form method="POST" action="/profile">
{{ csrf_field() }}...
</form>

也可以最新写法

<form method="POST" action="/profile">@csrf...
</form>

如果是AJAX提交:

在页面头部加上csrf-token:

<meta name="csrf-token" content="{{ csrf_token() }}">

提交headers中增加 X-CSRF-TOKEN:

$.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}
});

解决办法2: 移除 CSRF token

也可以在指定页面移除CSRF保护:

/app/Http/Middleware/VerifyCsrfToken.php

<?phpnamespace App\Http\Middleware;use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;class VerifyCsrfToken extends Middleware
{/*** The URIs that should be excluded from CSRF verification.** @var array*/protected $except = ['stripe/*','http://example.com/foo/bar','http://example.com/foo/*',];
}

参考链接:

http://blog.csdn.net/qq_37107603/article/details/78891628
https://laravel.com/docs/5.6/csrf#csrf-introduction

[END]

使用Laravel提交POST请求出现The page has expired due to inactivity错误相关推荐

  1. 使用Larave5.6l提交POST请求出现The page has expired due to inactivity错误

    使用Larave5.6l提交POST请求出现The page has expired due to inactivity错误 使用Larave5.6l提交POST请求出现The page has ex ...

  2. laravel 请求出现 post The page has expired due to inactivity.

    使用Laravel提交POST请求出现:The page has expired due to inactivity. Please refresh and try again. 这是由于在Larav ...

  3. Laravel框架post的路由出现The page has expired due to inactivity. Please refresh and try again.

    post提交数据时候显示如下: The page has expired due to inactivity. Please refresh and try again 这是由于在laravel框架中 ...

  4. laravel5.6 提示The page has expired due to inactivity. Please refresh and try again.的解决方法

    post提交数据时候显示如下: The page has expired due to inactivity. Please refresh and try again 这是由于在laravel框架中 ...

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

    post提交数据时候显示如下: The page has expired due to inactivity. Please refresh and try again123 这是由于在laravel ...

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

    The page has expired due to inactivity. Please refresh and try again. laravel5.6 开发API使用apipost调用路由时 ...

  7. laravel5.5 The page has expired due to inactivity. Please refresh and try again.

    报错: The page has expired due to inactivity. Please refresh and try again. 原因: 表单未添加CSRF验证,应添加{{ csrf ...

  8. laravel常见错误(一):The page has expired due to inactivity. Please refresh and try again.

    背景知识: 最近工作上使用了laravel框架,这个常见错误系列会记录我在学习和使用laravel时遇到的一些问题的场景和解决方法. laravel文档:传送门​​​​​​​ 错误场景:我在web.p ...

  9. laravel 5.5 The page has expired due to inactivity. Please refresh and try again

    在laravel框架中有此要求:任何指向 web 中 POST, PUT 或 DELETE 路由的 HTML 表单请求都应该包含一个 CSRF 令牌,否则,这个请求将会被拒绝 1.taiji/app/ ...

最新文章

  1. AtCoder Beginner Contest 198 (A ~ F)题解
  2. AIX 操作系统日常维护须知
  3. mysql事物日志工具_MySQL——常用工具和日志
  4. 将本地文件上传至Github【详细步骤】
  5. 【itext学习之路】--4.给pdf增加文本水印和图片水印
  6. linux终端怎样ise,Linux下ISE开发环境的安装zz
  7. C99中的变长数组(VLA)
  8. 定义枚举类型时指定其使用的大小 (C++,C#)
  9. hdu2844 Coins -----多重背包+二进制优化
  10. 微信小程序左右菜单mysql_微信小程序tab左右滑动切换功能的实现代码
  11. visual studio code写c语言是在include下有绿色的下划线提示not found
  12. 六石管理学:头目们为什么要忽略产品质量
  13. react在线文件_在线IDE开发入门之从零实现一个在线代码编辑器
  14. Android解析WindowManagerService(一)WMS的诞生
  15. leetcode 326 [easy]--- Power of Three
  16. 物联网(lot)特定场景最佳实践
  17. 如何修复 Windows 10 中任务栏消失的问题?
  18. Codeforces 106 Buns【多重背包】
  19. Power BI 中的货币换算
  20. 转行做程序员到底可不可行?转行前先考虑好以下几点

热门文章

  1. 批量保存西瓜无水印视频的方法步骤
  2. Mysql ERROR: 1253 解决方法
  3. 解决Win系统cad激活安装失败问题,AutoCad 2022 中文/英文正式详细安装教程
  4. 蔬菜类别二级计算机,国家标准:蔬菜分类.doc
  5. html魔方转动效果,简单说 用CSS做一个魔方旋转的效果
  6. 椭圆隐式方程和参数方程的互相转换
  7. 美通企业日报 | Gap在华门店总数突破200家;千禧一代环游世界的愿望超过买房...
  8. php弹幕反检测,【原理讲解附源码】找到B站弹幕的发送者
  9. 【计算机网络】计算机网络总结
  10. 玩转英伟达jetson系列(一)刷系统