我们创建了一个基于 PHP 的插件,它提供了一个 RESTful 接口,供我们正在开发的移动应用程序使用。该插件是自托管的,这意味着任何想要使用移动应用程序的人都必须在他们的服务器上安装这个 PHP 插件。我们的一位用户报告说,安装插件后他们无法登录。使用 Postman 练习登录请求中涉及的 API,我想出了以下内容:
请求
PUT http://<user's website>/index.php/wurrd/clientinterface/operator/login
{"username":"apple", "password":"dove", "clientid":"AABBB-CCCCC-DEFGHIJ", "deviceuuid":"aaa-uuu-isdi"}
响应
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>501 Method Not Implemented</title>
</head>
<body>
<h1>Method Not Implemented</h1>
<p>GET to /chat/index.php/wurrd/clientinterface/operator/login not supported.
<br />
</p>
<p>Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body>
</html>
API 不会为 GET 公开该路由,因此在尝试通过 GET 到达该路由时,错误消息是合适的。但是,问题是该请求是使用 PUT 发出的。
我不知道如何调查这个问题。服务器正在运行 Apache。可能是 .htaccess 有问题吗?我认为可能是一个mod_rewrite问题,但我想这应该处理 URL 而不是 HTTP 方法。
此外,路由是使用 Symfony2 路由组件完成的。
任何帮助将不胜感激。
谢谢。
更新 1:
这是Symfony路由的配置:
wurrd_client_operator_login:
# The login request details are passed in as a JSON payload.
path: /wurrd/clientinterface/operator/login
defaults:
_controller: Wurrd'Mibew'Plugin'ClientInterface'Controller'OperatorController::loginAction
methods: [PUT]
尝试向 URL 添加 _method 参数以强制使用该方法。
更多信息在这里:http://symfony.com/doc/current/cookbook/routing/method_parameters.html
如果正在进行未
被注意的 303 重定向(如果您的客户端未正确实现 HTTP,则也会发生 301/302(,或者如果代理/中间人正在转换请求到达服务器。
要使用 _method
,请确保没有任何内容禁用支持:http://symfony.com/doc/current/reference/configuration/framework.html#http-method-override