不允许使用 Slim Framework 方法。必须是以下之一:POST (405)

Slim Framework Method not allowed. Must be one of: POST (405)

我已经在 slim 框架中编写了 REST api。当我从浏览器调用 authenticate API 时,它通过 'Method not allowed. Must be one of: POST'。以下是我的代码,请指正我哪里错了。

Index.php

<?php

require 'vendor/autoload.php';
require 'Authenticate.php';

$app = new \Slim\App;

$app->post('/api/authenticate', \Authenticate::class);

$app->run();

.htaccess

RewriteEngine On
RewriteRule ^ index.php [QSA,L]

URL

http://localhost/project/api/authenticate

如果您在浏览器中键入 URL,方法将是 GET 而不是 POST。您可以做的是使用 Postman 或您选择的其他替代方法来测试您的 REST API 是否适用于其他方法,例如 POSTPUTDELETE 等。

有关 HTTP 方法的更多信息here

希望对您有所帮助!