2017-08-06 174 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或建立另一条路线,显示的页面,然后提交形式邮寄到预定航线

相关问题