gpt4 book ai didi

php - 为什么我的 PUT HTTP 请求会转换为 GET

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:27:33 25 4
gpt4 key购买 nike

我们创建了基于 PHP 的插件,它提供了一个 RESTful 接口(interface),供我们正在开发的移动应用程序使用。该插件是自托管的,这意味着任何想要使用移动应用程序的人都必须在他们的服务器上安装这个 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]

最佳答案

尝试将 _method 参数添加到 URL 以强制使用该方法。

更多信息在这里: http://symfony.com/doc/current/cookbook/routing/method_parameters.html

关于php - 为什么我的 PUT HTTP 请求会转换为 GET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35206521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com