我的網絡路由正在工作,但是我無法發佈到我的api路由,我收到MethodNotAllowedHttpException
。我認爲這是GET工作的csrf標記問題,但我無法弄清楚如何解決它。我正在使用郵差模擬API請求。Laravel 5.4 API路由
auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'devices',
],
],
RouteServiceProvider.php
protected function mapApiRoutes()
{
Route::middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
路由/ api.php
Route::post('api', ['uses' => '[email protected]']);
kernel.php
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'auth:api',
'bindings',
],
];
這是從舊版本的Laravel升級而來的,我通過安裝Laravel 5.4的全新副本升級,然後複製到我的代碼中,根據需要進行更改。
從哪裏和如何打電話?如果來自ajax共享該代碼? –
@ detective404我正在使用郵遞員來打電話。我打電話給www.mydomain.com/api POST請求 – meeeee
嗨@meeeee您是否找到了解決此問題的方法。我有類似的問題,如果它在你身邊解決,然後讓我知道。 –