当前位置:网站首页>A 419 error occurred in the laravel postman submission form. July 6th, 2020 diary.
A 419 error occurred in the laravel postman submission form. July 6th, 2020 diary.
2022-07-01 09:19:00 【What about your long love~】
Studying recently laraveel introduction , Learned the upload and download section , Because I haven't learned about controllers and views yet , So just use it. postman Mock submit form , Uploaded a small file .
But with postman When submitting forms and uploading files , appear 了 419 error , This is because csrf The limitation of . The result of Baidu solution is probably 3 individual
The first is to annotate the middleware :
app\Http\Kernel.php
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
// Comment out the following line
// \App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
The second way is Set the whitelist
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 = [
// Set... Here *
'*'
];
}
this 2 It's true that the function can be realized in three steps , But this 2 All of them are extreme , So I tried to set the white list for a certain method of a certain controller , It is written as follows
<?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 = [
// Set... Here *
// '*'
'[email protected]',
'index/index',
'www.blog.com/scc'
];
}
Tried three ways to write All wrong , use postman Upload file or 419 error , Later, the real solution was found .
<?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 = [
# This is the way the root is written in Miao Hong .
'scc'
];
}
scc Is the routing ID .
as follows
# Routing rules
Route::any('scc', '[email protected]');
# Method of controller
function scc(Request $request){
// echo csrf_token();
$name = $request->file('filename');
echo '<pre>';
print_r($name->path());
echo '</pre>';
echo '<hr>';
die;
}
、
边栏推荐
- Redis source code learning (29), compressed list learning, ziplist C (II)
- Mysql8.0 learning record 17 -create table
- 【pytorch】transforms. Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
- 树结构---二叉树1
- Shell script -while loop explanation
- Pain points and solutions of equipment management in large factories
- 闭包实现迭代器效果
- js变量提升(hoisting)
- Log4j 日志框架
- 【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + DHT11 +NodeJs本地服务+ MySQL数据库
猜你喜欢
Tree structure -- binary tree 2 non recursive traversal
Understanding and implementation of AVL tree
[video game training] real topic of 2013 video game of infrared optical communication device
【pytorch】softmax函数
ESP8266 FreeRTOS开发环境搭建
Why is the Ltd independent station a Web3.0 website!
[pytorch] softmax function
MySQL optimization
3D printing Arduino four axis aircraft
FAQ | FAQ for building applications for large screen devices
随机推荐
手指点击屏幕就模拟进入F11进入全屏
ES6-const本质与完全不可改实现(Object.freeze)
2.3 [kaggle dataset - dog feed example] data preprocessing, rewriting dataset, dataloader reading data
Redis source code learning (29), compressed list learning, ziplist C (II)
树结构---二叉树1
美团2022年机试
Design and manufacture of simple digital display electronic scale
OSPF - virtual link details (including configuration commands)
3D printing Arduino four axis aircraft
dsPIC30F6014a LCD 方块显示
Preparing for the Blue Bridge Cup -- bit operation
Meituan machine test in 2022
[pytorch] softmax function
【pytorch学习】torch.device
Flink面试题
Shell script - array definition and getting array elements
Principle and application of single chip microcomputer timer, serial communication and interrupt system
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + MQ系列 + NodeJs本地服务 + MySql存储
NoSQL数据库的安装和使用
【电赛训练】红外光通信装置 2013年电赛真题