[英]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 我尝试过的事情的运行清单
Route::group(['middleware' => 'web'], function () {
Route::group(['middleware' => 'web'], function () {
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.