【发布时间】:2018-06-15 13:53:13
【问题描述】:
我使用 Dingo 和 Laravel 5.1 创建简单的 API。
所以在 route.php 我有:
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', function($api) {
$api->get('getvoucher', 'App\Http\Controllers\BitemsController@index');
$api->get('update/{key}', 'App\Http\Controllers\BitemsController@update');
$api->post('store', 'App\Http\Controllers\BitemsController@store');
$api->post('authenticate', 'App\Http\Controllers\AuthenticateController@authenticate');
$api->post('logout', 'App\Http\Controllers\AuthenticateController@logout');
$api->get('token', 'App\Http\Controllers\AuthenticateController@getToken');
});
我的 BitemsController 是:
public function index(Request $request)
{
$bitem = Bitem::where('key',$request->key)->where('id',$request->pin)->first();
return $bitem;
}
public function store(Request $request)
{
$bitem = new Bitem($request->all());
$bitem->save;
return $bitem;
}
现在我使用 POSTMAN 应用程序测试 API,当我向 localhost:8888/api/getvoucher 发送 GET 时一切正常,但是当我发出 POST 请求以存储一些数据时出现错误:
"message": "500 Internal Server Error",
"status_code": 500,
"debug": {
"line": 53,
"file": "C:\\wamp\\www\\dine\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken.php",
"class": "Illuminate\\Session\\TokenMismatchException",
"trace": [
为了解决这个问题我尝试添加:
protected $except = [
'api/*',
];
在中间件 VerifyCsrfToken.php 中,但无法正常工作。
请告诉我如何解决我的问题...
【问题讨论】:
-
任何想法如何解决问题?同样的错误出现在 api/authenticate POST route ...
-
您能否验证您的应用程序正在使用您的扩展
VerifyCsrfToken.php中间件? -
是的,我正在使用它......在内核中
标签: php laravel csrf middleware dingo-api