Laravel cURL POST抛出TokenMismatchException

ran*_*tan 3 php rest curl laravel-5

我对我的应用程序的POST cURL请求有问题.目前,我正在使用laravel 5构建RESTFUL注册功能.

这个例子的路线是

localhost:8000/user/create

我在终端上使用cURL函数传递值

curl -d 'fname=randy&lname=tan&id_location=1&email=randy@randytan.me&password=randytan&remember_token=Y&created_at=2015-03-03' localhost:8000/auth/register/
Run Code Online (Sandbox Code Playgroud)

这是我的routes.php

Route::post('user/create', 'UserController@create');

这是我存储注册用户的功能

public function create()
    {
        //function to create user.
        $userAccounts = new User;
        $userAccounts->fname = Request::get('fname');
        $userAccounts->lname = Request::get('lname');
        $userAccounts->id_location = Request::get('id_location');
        $userAccounts->email = Request::get('email');
        $userAccounts->password = Hash::make(Request::get('password'));
        $userAccounts->created_at = Request::get('created_at');

        $userAccounts->save();

        return Response::json(array(
                'error' => false,
                'user'  => $userAccounts->fname . " " . $userAccounts->lname
            ), 200);

    }
Run Code Online (Sandbox Code Playgroud)

执行上面的cURL语法,我收到此错误 TokenMismatchException

你有什么想法?

因为我只在我的几个网址中实现中间件,而且这个cURL注册网址并没有严格执行任何身份验证机制.

谢谢你.

Moh*_*eja 10

在Laravel 5(最新版本)中,您可以在/app/Http/Middleware/VerifyCsrfToken.php中指定要排除的 路由.

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'rest-api/*', # all routes to rest-api will be excluded.
    ];


}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.