2017-08-06 97 views
0

我正在Laravel開發護照API。我得到一個「MethodNotAllowedHttpException」。如何在Laravel中解決「MethodNotAllowedHttpException」錯誤?

enter image description here

我沒有得到任何想法,有什麼解決做我必須做的。

<?php 

use Illuminate\Http\Request; 

/* 
|-------------------------------------------------------------------------- 
| API Routes 
|-------------------------------------------------------------------------- 
| 
| Here is where you can register API routes for your application. These 
| routes are loaded by the RouteServiceProvider within a group which 
| is assigned the "api" middleware group. Enjoy building your API! 
| 
*/ 
Route::post('register', 'Api\Auth\[email protected]'); 
Route::post('login', 'Api\Auth\[email protected]'); 
Route::post('refresh', 'Api\Auth\[email protected]'); 

Route::middleware('auth:api')->group(function() { 
    Route::post('logout', 'Api\Auth\[email protected]'); 
    Route::get('posts', 'Api\[email protected]'); 
}); 
+0

當在瀏覽器中訪問'register',使用了'GET' ,但你的路線只允許'POST'。你可能需要'curl'或Postman來測試你的API。 – halfer

+0

我也有同樣的問題,你找到任何解決方案,請讓我知道。 – Abhee

回答

0

可能是由於在路由請求類型(GET/POST)失配和在視圖

  • 檢查,如果請求類型匹配在您的API調用或形式標籤的請求類型這個錯誤在你的路線文件並在APIcall
0

看,你使用你的路線「後」的方法:

Route::post('register', 'Api\Auth\[email protected]'); 

而瀏覽器的默認值是'get'。您是否嘗試顯示註冊表單或您是否正在向該路線提交表單。

要麼你應該改變這條路線爲GET或建立另一條路線,顯示的頁面,然後提交形式郵寄到預定航線

相關問題