Laravel提交POST请求报错
提交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请求报错的更多相关文章
- JS请求报错:Unexpected token T in JSON at position 0
<?php /* 最近做一个ajax validate表单验证提交的代码,在ajax提交的时候 JS请求报错:Unexpected token T in JSON at position 0 描 ...
- 【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.原因,工作队列被占用,只需 ...
- 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 ...
- 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 ...
- nuget包管理nuget服务器发布包时出现请求报错 406 (Not Acceptable)
在window服务器上部署nuget服务器时,发布包时出现请求报错 406 (Not Acceptable) 验证用户名.密码正确的情况下,还是出现上面错误.后面跟踪服务器日志,发现window\te ...
- 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 ...
- git https 请求报错 504
git https 请求报错 504 原因可能是因为设置了代理,ubuntu/deepin 系统可以检查 /etc/profile ~/.bashrc 内有没有设置 https 的代理. 有的话,去掉 ...
- Android版本28使用http请求报错not permitted by network security policy
Android版本28使用http请求报错not permitted by network security policy android模拟器调试登录的时候报错 CLEARTEXT communic ...
- 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 ...
随机推荐
- python:count 函数
API 一.string 中 某字符 的次数 str.count(sub, start= 0,end=len(string)) Args Annotations sub 搜索的子字符串 start 字 ...
- JDK1.8+API+中文文档+高清完整版(不要积分 免费拿)
JDK1.8+API+中文文档+高清完整版+CHM帮助文档 链接: https://pan.baidu.com/s/1LbdWSZ4qFjWXdJ88bXkn5w 提取码: frew 希望能帮上大家的 ...
- httpClient4.5.2工具类总结
使用背景: 因项目使用非结构化存储,http相关jar包统一升级到httpClient4.5.2,查阅相关文档总结如下,以咨分享,望不吝指教. 依赖jar包 httpclient-4.5.2.jar. ...
- css3 加载动画
代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8& ...
- 第四小节之Java 集合类
Java的集合类就像一个容器,专门用来存储Java类的对象.这些类可以存储任意类型的对象,并且长度可变,统称为集合,这些类位于java.util包中,数组也可以保存多个对象,但在某些情况下无法确定到底 ...
- php 简单删除提示
下面是别的网友整理的,大同小异.一般通过弹出确认按钮来判断是否继续进入下面的删除页面. 第一种: <a href="javascript:if(confirm('确认删除吗?'))wi ...
- mysql5.7.26做主主配置
一.首先两台服务器安装好mysql数据库环境 参照linux rpm方式安装mysql5.1 https://www.cnblogs.com/sky-cheng/p/10564604.html 二.在 ...
- JavaScript调试技巧之断点调试
首先,在各个浏览器中,断点调试支持的最好的当然是Firefox,Firefox不仅可以使用Firebug调试页面js脚本,还可以用高级调试工具例如JavaScript Debugger (Venkma ...
- PHP判断邮箱地址是否合法的正则表达式
PHP判断邮箱地址是否合法的正则表达式: function checkEmail($inAddress){ return (preg_match("/^([a-zA-Z0-9_-])+@([ ...
- $.getJSON同步和异步
$.ajaxSettings.async = false; $.getJSON(url, data, function(data){ }); $.getJSON(url, data, function ...