gpt4 book ai didi

php - Laravel cURL POST 抛出 TokenMismatchException

转载 作者:可可西里 更新时间:2023-11-01 00:00:09 27 4
gpt4 key购买 nike

我的应用程序的 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com