我在我的laravel应用程序中将数据发布到api路径,但是我收到了这个错误:
我是laravel的新手,我不知道这个问题的根源,或者在哪里检查这个错误的来源。
有人能帮忙吗?
[2015-03-29 12:05:49] local.ERROR: 500 - Exception @ /api/grades
exception 'Illuminate\Session\TokenMismatchException' in D:\xampp\htdocs\widgetsRepository\app\filters.php:98
Stack trace:
#0 [internal function]: {closure}(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#1 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php(199): call_user_func_array(Object(Closure), Array)
#2 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php(154): Illuminate\Events\Dispatcher->fire('router.filter: ...', Array, true)
#3 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Routing\Router.php(1473): Illuminate\Events\Dispatcher->until('router.filter: ...', Array)
#4 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(240): Illuminate\Routing\Router->callRouteFilter('csrf', Array, Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#5 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(114): Illuminate\Routing\ControllerDispatcher->callFilter(Array, Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#6 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(55): Illuminate\Routing\ControllerDispatcher->before(Object(classifications\api\GradeController), Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'store')
#7 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Routing\Router.php(967): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'classifications...', 'store')
#8 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#9 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Routing\Route.php(109): call_user_func_array(Object(Closure), Array)
#10 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Routing\Router.php(1033): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#11 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Routing\Router.php(1001): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#12 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(775): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#13 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(745): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#14 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Session\Middleware.php(72): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#15 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Cookie\Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#16 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Cookie\Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#17 D:\xampp\htdocs\widgetsRepository\vendor\stack\builder\src\Stack\StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#18 D:\xampp\htdocs\widgetsRepository\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(641): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#19 D:\xampp\htdocs\widgetsRepository\public\index.php(49): Illuminate\Foundation\Application->run()
#20 {main} [] []
修改
我在我的表单中发送_token,如下所示:
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
答案 0 :(得分:0)
您的路由受CSRF令牌保护。
您需要在API调用中提供CSRF令牌 - 或者您需要让该路由不再受CSRF检查保护。
答案 1 :(得分:0)
您是否检查过表单中是否设置了令牌?可能它是空的。