为什么我会收到“由于不活动,该页面已过期”。在我的API?

问题描述:

我试图用邮差在我的API来发布的Json但我得到一个错误:为什么我会收到“由于不活动,该页面已过期”。在我的API?

The page has expired due to inactivity.

所以,邮递员,我访问http://localhost:8000/api/jobs/。在我的头选项卡,我使用的内容类型的关键和应用/ JSON作为值和插入下面的JSON:

{"title": "PHP Developer/Laravel Expert","description": "Laravel Expert", "local": "São Paulo", "remote": "no", "company_id": "3"} 

我使用laravel。 这是我的web.php路由文件:

Route::group(array('prefix' => 'api'), function() { 
Route::get('/', function() { 
    return response()->json(['message' => 'Jobs API', 'status' => 'Connected']); 
}); 

Route::resource('jobs', 'JobsController'); 
Route::resource('companies', 'CompaniesController'); 

});

这里是我的CompaniesController存储方法:

public function store(Request $request) 
{ 
    $job = new Job(); 
    $job->fill($request->all()); 
    $job->save(); 

    return response()->json($job, 201); 
} 

我认为您使用的是web.php laravel版> 5.3而是写API路线写在路线的api.php API路线夹。

The api.php file contains routes that the RouteServiceProvider places in the api middleware group, which provides rate limiting. These routes are intended to be stateless, so requests entering the application through these routes are intended to be authenticated via tokens and will not have access to session state.

Route Directory in laravel

如果你有laravel 5.5,并希望从中删除路由CSRF保护,那么你可以在app \的Http添加到$except = []; \中间件\ VerifyCsrfToken。

尽管如此,您可能还是希望采用其他形式的身份验证。