Slim Framework:方法不允许 方法不允许。必须是以下之一:POST

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

我正在 PHP 中设置一个 REST 服务器,并希望允许客户端使用具有不同方法的端点,例如 GET、POST、PUT、DELETE,... 但是当我尝试为 POST 方法添加函数时出现问题:如果我尝试通过 Postman 使用 POST 访问它,应用程序将运行 GET 函数。

我已经尝试评论 GET 函数,但如果我这样做,我会收到错误 405。

// Just a testing function for POST
$app->post('/users', function (Request $request, Response $response, array $args)
{
    $user = $request->getParsedBody();
    $response->getBody()->write(json_encode($user->getWrapperClass()));
    return $response->withHeader('Content-Type', 'application/json');
});

谁能帮帮我?

我发现了问题:不是 Postman 也不是我的代码。问题是在 Postman 中输入的 URL:它是一个 http URL 并且服务器自动重定向到 https。在此过程中,HTTP 方法只是更改为 GET 而不是 POST、PUT 或其他任何方式...现在将 URL 更改为 https:现在工作正常!