不允许使用Slim Framework Method。必须为以下之一:POST(405) [英] Slim Framework Method not allowed. Must be one of: POST (405)
问题描述
我已经在苗条的框架中编写了REST api。当我从浏览器调用身份验证API时,它会显示不允许的方法。必须是以下其中一种:POST 。下面是我的代码,请纠正我哪里出错了。
I have written REST api in slim framework. When i call authenticate API from browser it troughs 'Method not allowed. Must be one of: POST'. Below is my code, please correct me where i went wrong.
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的其他方法,例如 POST
, PUT
, DELETE
等。
if you type the URL in the browser, the method is going to be GET
instead of POST
. What you can do is use Postman or other alternatives of your choice to test your REST API for other methods like POST
, PUT
, DELETE
, etc.
More info about HTTP methods here
希望它会有所帮助!
这篇关于不允许使用Slim Framework Method。必须为以下之一:POST(405)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!