VerifyCsrfToken始终在路由到API中间件Laravel 5.2.35时调用 [英] VerifyCsrfToken always called when route to API Middleware Laravel 5.2.35
问题描述
protected $ middlewareGroups = [
'web'=> [
\App\Http\Middleware\EncryptCookies :: class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse :: class,
\Illuminate\ Session \Middleware\StartSession :: class,
\Illuminate\View\Middleware\ShareErrorsFromSession :: class,
\App\Http\Middleware\VerifyCsrfToken :: class ,
],
'api'=> [
'throttle:60,1',
],
];
但是,VerifyCsrfToken总是被调用,尽管我把路由放入 api
middlewareGroup。
我在Advanced REST Client中检查请求标题。我找到了这个。
第一个项目结果:
第二个项目结果:
第一个结果在请求标题中有cookie属性,但第二个结果没有
如果打开RouteServiceProvider你会看到这发生了什么。检查 I have two similiar Laravel project. This is part code of kernel.php. Both projects have same code. But, VerifyCsrfToken always be called although I put my route inside I check request header in Advanced REST Client. I found this. First project result :
Second project result :
First result has cookie attribute in request header, but second result doesn't have All the routes in If you open up your RouteServiceProvider you will see where this is happening. Check the 这篇关于VerifyCsrfToken始终在路由到API中间件Laravel 5.2.35时调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
map
方法以查看调用 mapWebRoutes
。protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
],
'api' => [
'throttle:60,1',
],
];
api
middlewareGroup.routes.php
are included in a route group which has the 'web' middleware applied. You should probably create another routes file and have the RouteServiceProvider load those in a group with 'api' and without the 'web' middleware applied.map
method to see it calling mapWebRoutes
.