[英]Laravel5.2 Unwanted VerifyCsrfToken
我設置了新的L5.2,更改后的路由文件如下所示:
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::group(['middleware' =>'api', 'prefix' => '/api/v1'], function () {
Route::post('/api/v1/login', 'Api\V1\Auth\AuthController@postLogin');
});
當我去郵遞員TokenMismatchException in VerifyCsrfToken.php line 67
: http : TokenMismatchException in VerifyCsrfToken.php line 67
我得到: TokenMismatchException in VerifyCsrfToken.php line 67
但是我的內核文件看起來像這樣:
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”中間件組中(而不是“ Web”,此處為VerifyCsrfToken),但令人驚訝的是我遇到了以上錯誤。 所以我想知道-wtf? 怎么樣呢? 是否始終執行“ Web”中間件組(針對每個請求)?
默認情況下,看起來所有路由都包裹在“ web”組中。
在RouteServiceProvider
有此功能。
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
protected function mapWebRoutes(Router $router)
{
$router->group([
'namespace' => $this->namespace, 'middleware' => 'web',
], function ($router) {
require app_path('Http/routes.php');
});
}
如果要特定的uri不檢查CSRF令牌,請轉到App\\Http\\Middleware\\VerifyCsrfToken
並將uri添加到$except
數組中。
您還可以使用CLI和php artisan route:list
來查看哪些中間件后面的路由。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.