"The GET method is not supported for this route. Supported methods: POST" 我的消息 laravel API

"The GET method is not supported for this route. Supported methods: POST" message in my laravel API

我按照教程使用外部 api 创建登录页面,但我的 API 无法正常工作。

在本地主机 http://localhost:8000/api/auth/login 出现 "The GET method is not supported for this route. Supported methods: POST." 并在 Chrome DevTools

headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
message: "Http failure response for http://127.0.0.1:8000/api/auth/register: 422 Unprocessable Entity"
name: "HttpErrorResponse"
ok: false
status: 422
statusText: "Unprocessable Entity"
url: "http://127.0.0.1:8000/api/auth/register" 

我用laravel 6,php7,离子4

请帮帮我!

(教程是:https://blog.flicher.net/laravel-rest-api-passport-authentication-for-ionic-app/

如果您按照 Step 6 — Set API routes 部分中的教程进行操作,它会列出 api.

的所有路线

这里是这样写的

File: api.php 

Route::group([
    'prefix' => 'auth'
], function () {
    Route::post('login', 'Auth\AuthController@login')->name('login');
});

这意味着我们有一个名称为 login 的路由,这将是一个 POST 请求,而 url 将是 api/auth/login,因为它是 api.php文件。

您是从浏览器调用它,那将是一个 get 请求,laravel 在路由中找不到它,因此它会生成此错误。

参考:Laravel Routing