提交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

 <?php

 namespace 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/*',
];
}

Laravel提交POST请求报错的更多相关文章

  1. JS请求报错:Unexpected token T in JSON at position 0

    <?php /* 最近做一个ajax validate表单验证提交的代码,在ajax提交的时候 JS请求报错:Unexpected token T in JSON at position 0 描 ...

  2. 【svn】在提交文件是报错:previous operation has not finished;run 'cleanup' if it was interrupted

    1.svn在提交文件是报错:previous operation has not finished;run 'cleanup' if it was interrupted2.原因,工作队列被占用,只需 ...

  3. Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

    Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport Xcode7 beta 网络请求报错:The ...

  4. Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport

    Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport Xcode7 beta 网络请求报错:The ...

  5. nuget包管理nuget服务器发布包时出现请求报错 406 (Not Acceptable)

    在window服务器上部署nuget服务器时,发布包时出现请求报错 406 (Not Acceptable) 验证用户名.密码正确的情况下,还是出现上面错误.后面跟踪服务器日志,发现window\te ...

  6. Django报错:提交表单报错---RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have APPEND_SLASH set.

    Django报错:提交表单报错---RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and ...

  7. git https 请求报错 504

    git https 请求报错 504 原因可能是因为设置了代理,ubuntu/deepin 系统可以检查 /etc/profile ~/.bashrc 内有没有设置 https 的代理. 有的话,去掉 ...

  8. Android版本28使用http请求报错not permitted by network security policy

    Android版本28使用http请求报错not permitted by network security policy android模拟器调试登录的时候报错 CLEARTEXT communic ...

  9. Django:提交表单报错:RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have A

    Django:提交表单报错:RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you ...

随机推荐

  1. 02:Redis常见面试题

    1.1 redis基础面试题 1.什么是Redis?简述它的优缺点? 1. Redis本质上是一个Key-Value类型的内存数据库,很像memcached. 2. 整个数据库统统加载在内存当中进行操 ...

  2. flask中使用jsonify和json.dumps的区别

    一.实验 python的flask框架为用户提供了直接返回包含json格式数据响应的方法,即jsonify,在开发中会经常用到.如下一段简单的flask后端代码,服务端视图函数根据请求参数返回json ...

  3. [转载]Ubuntu环境下检查CPU 的温度

    原文地址:https://www.linuxprobe.com/ubuntu-cpu-temperature.html 我们将使用一个GUI工具Psensor,它允许你在Linux中监控硬件温度.用P ...

  4. java学习笔记(4)多态

    一.多态 --------------------------------------------- 1.定义:某一类事物的多种存在形态 例如:动物中猫,狗. 猫这个对象对应的类型是猫类型 猫 x  ...

  5. redis之使用场景

    随着数据量的增长,MySQL 已经满足不了大型互联网类应用的需求.因此,Redis 基于内存存储数据,可以极大的提高查询性能,对产品在架构上很好的补充.在某些场景下,可以充分的利用 Redis 的特性 ...

  6. 017-zabbix_proxy分布式监控部署

    一.proxy分布式监控介绍 来源于zabbix官网: https://www.zabbix.com/documentation/3.4/zh/manual/distributed_monitorin ...

  7. 怎样减少 Android 应用包 60% 的大小?

    简评: 应用的大小也是用户体验的一个重要方面,而减少 Android 应用安装包大小其实一点也不复杂. 对于移动应用来说,应用安装包的大小当然是越小越好.特别是对于一些欠发达地区,你不希望用户因为手机 ...

  8. Lindström–Gessel–Viennot lemma

    解决不相交路径计数 有两个大小为N的点集A,B A上每一个点对应着B的每一个点 求满足条件的路径集合有多少个 图里面可能还有一些障碍 Codeforces 348 D 有一个N*M的网格图 有两个点 ...

  9. C语言实现栈代码

    /* 栈的特性:先进后出. 栈在计算语言处理和将递归算法改为非递归算法等方面起着非常重要的作用. */ #define INITSIZE 100 //储存空间的初始分配量 typedef int El ...

  10. Prism MVVM使用WPF的DataGrid控件

    此项目源码下载地址:https://github.com/lizhiqiang0204/PrismDataGird01 运行效果如下 前端代码如下 <Window x:Class="V ...