php - Laravel cURL POST 抛出 TokenMismatchException

标签 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/

这是我的 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);

    }

执行上面的 cURL 语法时,出现此错误 TokenMismatchException

你有什么想法吗?

因为我只在我的几个 url 中实现了中间件,并且这个 cURL 注册 url 没有紧密地融入任何身份验证机制。

先谢谢了。

最佳答案

在 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.
    ];


}

希望这对您有所帮助。

关于php - Laravel cURL POST 抛出 TokenMismatchException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29192806/

相关文章:

php - 在Web服务器上部署Flex应用程序问题

javascript - 我没有得到 Nodejs npm 包 https 的 https.get() 与 https.request() 方法之间的区别

http - 使用 curl 时在 meteorjs 中发布数据

php - 将注释放在可创建语句的中间

javascript - PHP $_GET 无法与 JQuery Mobile 一起使用

java - Jersey 应用程序 404 未找到错误

sql-server - 在连接关闭的情况下在 SQL Server 上保持事务打开

php - 下载 xml 时 curl 超时

cURL 链接错误 “unresolved external symbol _Curl_base64_enode”

php - 从数组中删除重复值