Why does my PUT HTTP request get converted to a GE

2019-08-12 04:51发布

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]

2条回答
三岁会撩人
2楼-- · 2019-08-12 05:40

This may also happen if there is an unnoticed 303 redirect going on (and also 301/302 if your client doesn't implement HTTP properly), or if a proxy/man-in-the-middle is transforming the request before it reaches the server.

To use _method, make sure nothing is disabling support: http://symfony.com/doc/current/reference/configuration/framework.html#http-method-override

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-08-12 05:51

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

查看更多
登录 后发表回答