当前位置:网站首页>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;
}
、
边栏推荐
- Tree structure --- binary tree 1
- Win7 pyinstaller reports an error DLL load failed while importing after packaging exe_ Socket: parameter error
- [pytorch learning] torch device
- 【检测技术课案】简易数显电子秤的设计与制作
- 2.2 【pytorch】torchvision. transforms
- 计网01-物理层
- 【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云和Arduino的化学环境系统检测,支持钉钉机器人告警
- JS functionarguments object
- [pytorch] 2.4 convolution function nn conv2d
- How to launch circle of friends marketing and wechat group activities
猜你喜欢
js作用域链与闭包
Why is the Ltd independent station a Web3.0 website!
【pytorch】softmax函数
【检测技术课案】简易数显电子秤的设计与制作
nacos简易实现负载均衡
How to manage fixed assets efficiently in one stop?
[video game training] real topic of 2013 video game of infrared optical communication device
Nacos service configuration and persistence configuration
Design and manufacture of simple digital display electronic scale
队列的实现和应用
随机推荐
樹結構---二叉樹2非遞歸遍曆
How to manage fixed assets efficiently in one stop?
[pytorch] 2.4 convolution function nn conv2d
laravel postman 提交表单出现419错误。2020年7月6日记。
【pytorch】nn.AdaptiveMaxPool2d
Mysql 优化
【pytorch】transforms. Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
Principles of Microcomputer - Introduction
Jetson nano installs tensorflow GPU and problem solving
js this丢失问题分析 及 解决方案
OSPF - virtual link details (including configuration commands)
LeetCode 344. Reverse string
Redis source code learning (29), compressed list learning, ziplist C (II)
Analysis and solution of JS this loss
2.4 激活函数
ES6 const essence and completely immutable implementation (object.free)
How to realize the usage of connecting multiple databases in idel
es6-顶层对象与window的脱钩
pcl_viewer命令
【pytorch】nn. AdaptiveMaxPool2d