简体   繁体   English

使用Route :: post()在VerifyCsrfToken.php第67行中的TokenMismatchException

[英]TokenMismatchException in VerifyCsrfToken.php line 67 using Route::post()

I understand that this is a common issue with Laravel 5.x, but my particular run-in with the problem is not through submitting a form. 我知道这是Laravel 5.x的常见问题,但是我遇到的特殊问题不是通过提交表单。 Instead, I am using postman to send data to a URL endpoint to test if data is successfully received. 相反,我使用邮递员将数据发送到URL端点以测试是否成功接收到数据。 I'm working with Laravel 5.2 and I'm very much new to it! 我正在使用Laravel 5.2,它是我的新手!

Here is my routes.php file (related content) 这是我的routes.php文件(相关内容)

Route::group(['middleware' => 'web'], function () {
    Route::post('/cart', 'CartController@buildcart');
});

Here is my CartController.php (entire file) 这是我的CartController.php(整个文件)

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class CartController extends Controller
{
    public function buildcart(){
        echo 'hello';
    }
}

As simple as that is, when I use postman to send random data to the /cart URL, I get 就这么简单,当我使用邮递员将随机数据发送到/ cart URL时,我得到

TokenMismatchException in VerifyCsrfToken.php line 67:

Can anyone help me understand why this is failing? 谁能帮助我了解为什么失败了? I don't see how using 我看不到如何使用

{{ csrf_token() }}

is the solution for this case since the data is coming from an external source. 对于这种情况,这是解决方案,因为数据来自外部来源。

Running list of things I've tried 我尝试过的事情的运行清单

  • Removing the route from Route::group(['middleware' => 'web'], function () { Route::group(['middleware' => 'web'], function () {
  • using Route::group(array('before' => 'csrf', ['middleware' => 'web']), function () { 使用Route::group(array('before' => 'csrf', ['middleware' => 'web']), function () {

try add the route to this route group 尝试将路线添加到该路线组

  Route::group(array('before' => 'csrf', ['middleware' => 'web']), function () {

 Route::post('/cart', 'CartController@buildcart');

 });

EDIT : try to comment this line in app\\kernel.php 编辑:尝试在app \\ kernel.php中注释此行

   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',
    ],
];

Try changing the middleware in the routes.php file. 尝试更改routes.php文件中的中间件。 I think, you are getting the error as you are not authorized to use the route. 我认为,由于您无权使用该路由,因此出现了错误。 Try this: 尝试这个:

Route::group(['middleware' => 'guest'], function () {
    Route::post('/cart', 'CartController@buildcart');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel 5-VerifyCsrfToken.php 67行中的TokenMismatchException - Laravel 5 - TokenMismatchException in VerifyCsrfToken.php line 67 VerifyCsrfToken.php 67行中的错误TokenMismatchException: - Error TokenMismatchException in VerifyCsrfToken.php line 67: 使用ajax在laravel上的VerifyCsrfToken.php第67行中的TokenMismatchException - TokenMismatchException in VerifyCsrfToken.php line 67 on laravel using ajax PHP Laravel:VerifyCsrfToken.php 67行中的TokenMismatchException - PHP Laravel : TokenMismatchException in VerifyCsrfToken.php line 67 错误:laravel 5.2中VerifyCsrfToken.php第67行中的TokenMismatchException - Error: TokenMismatchException in VerifyCsrfToken.php line 67 in laravel 5.2 上传视频时,VerifyCsrfToken.php 67行中的TokenMismatchException - TokenMismatchException in VerifyCsrfToken.php line 67 when uploading video 如何在Laravel 5.2中的VerifyCsrfToken.php 67行中修复TokenMismatchException - how to fix TokenMismatchException in VerifyCsrfToken.php line 67 in laravel 5.2 Laravel 5.2-VerifyCsrfToken.php 67行中的TokenMismatchException: - Laravel 5.2 - TokenMismatchException in VerifyCsrfToken.php line 67: VerifyCsrfToken.php 67行中的TokenMismatchException:在Laravel 5.2中 - TokenMismatchException in VerifyCsrfToken.php line 67: in Laravel 5.2 如何解决VerifyCsrfToken.php第67行中的TokenMismatchException - How to solve TokenMismatchException in VerifyCsrfToken.php line 67
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM