为什么我的PUT HTTP请求得到转换为GET [英] Why does my PUT HTTP request get converted to a GET

查看:439
本文介绍了为什么我的PUT HTTP请求得到转换为GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们创建的基于PHP的插件,提供用于由我们正在开发一个移动应用程序一个RESTful接口。这个插件是自托管的,这意味着任何人谁愿意使用移动应用有自己的服务器上安装此插件PHP。我们的一个用户报道称,安装他们无法登录插件后。使用邮差行使参与登录请求API的,我想出了以下内容:

请求

  PUT HTTP://<使用者的网站> /index.php/wurrd/clientinterface/operator/login
{用户名:苹果,密码:鸽子,的clientid:AABBB-CCCCC-DEFGHIJ,deviceuuid:AAA级UUU-isdi}

响应

 <!DOCTYPE HTML PUBLIC -  // IETF // DTD HTML 2.0 // ENGT&;
< HTML和GT;
< HEAD>
    <标题> 501方法未实现< /标题>
< /头>
<身体GT;
    < H1>方法未实现< / H1>
    < P>取到/chat/index.php/wurrd/clientinterface/operator/login不支持。
        < BR />
    &所述; / P>
    < P>此外,试图使用ErrorDocument来处理请求时遇到一个404 Not Found错误< / P>
< /身体GT;
< / HTML>

该API不公开的获取途径,因此试图通过GET到那里时,该错误信息是适当的。然而,问题是,该请求用一个PUT制成。

我在一个头绪来调查该问题。服务器运行Apache。难道是用.htaccess的问题吗?我觉得可能是一个mod_rewrite的问题,但我想这应该处理的URL,而不是HTTP方法。

此外,路由使用Symfony2的路由组件完成。

任何帮助将是AP preciated。

感谢。

更新1:

这是symfony的路由配置:

  wurrd_client_operator_login:
    #登录请求细节传过来的JSON有效载荷。
    路径:/ wurrd / clientinterface /运营/登录
    默认值:
        _controller:Wurrd \\ Mibew \\插件\\ ClientInterface \\控制器\\ OperatorController ::在loginAction
    方法:PUT]


解决方案

尝试添加_method参数的URL来强制方法。

此处了解详情:
http://symfony.com/doc/current/cookbook/routing/method_parameters.html

We created PHP-based plugin that provides a RESTful interface that is used by a mobile app that we are working on. The plugin is self-hosted, meaning anyone who wants to use the mobile app has to install this PHP plugin on their server. One of our users is reporting that after installing the plugin they fail to login. Using Postman to exercise the APIs involved in the login request, I came up with the following:

REQUEST

PUT http://<user's website>/index.php/wurrd/clientinterface/operator/login
{"username":"apple", "password":"dove", "clientid":"AABBB-CCCCC-DEFGHIJ", "deviceuuid":"aaa-uuu-isdi"}

RESPONSE

<!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>

The API doesn't expose that route for a GET, so the error message is appropriate when trying to get there via a GET. However, the issue is that the request was made with a PUT.

I am at a loss as to how to investigate the issue. The server is running Apache. Could it be a problem with the .htaccess? I thought may be a mod_rewrite issue, but I guess this should deal with the URL and not the HTTP method.

Also, routing is done using the Symfony2 routing component.

Any help would be appreciated.

Thanks.

Update 1:

This is the configuration of the Symfony route:

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]

解决方案

Try adding a _method parameter to the URL to force the method.

More info here: http://symfony.com/doc/current/cookbook/routing/method_parameters.html

这篇关于为什么我的PUT HTTP请求得到转换为GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆