【问题标题】:"The GET method is not supported for this route. Supported methods: POST" message in my laravel API“这条路线不支持 GET 方法。支持的方法:POST”消息在我的 laravel API 中
【发布时间】:2020-01-13 13:01:48
【问题描述】:

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

在 localhost http://localhost:8000/api/auth/login 中出现“此路由不支持 GET 方法。支持的方法: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,php 7,离子 4

请帮帮我!

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

【问题讨论】:

  • 检查您的路线。在 cmd 或终端的根目录下运行 php artisan route:list。检查给定路线的http verb

标签: laravel api ionic4


【解决方案1】:

如果您按照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

【讨论】:

    猜你喜欢
    • 2021-12-31
    • 2019-12-17
    • 1970-01-01
    • 2019-10-12
    • 2021-04-11
    • 1970-01-01
    • 2021-06-17
    • 2021-12-23
    • 1970-01-01
    相关资源
    最近更新 更多