405方法不允许-PUT(PHP)

我在向我的API发送PUT请求时遇到问题。我得到了回应: “ 405方法不允许。此URL不允许使用请求的方法PUT。”

在我的htaccess中,我有:

<Limit GET POST OPTIONS>
  Order allow,deny
Allow from all
</Limit>

在php文件中,我有:

<?php
header('access-control-allow-origin: *');

    if (isset ($_GET['action']))
    {
        if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS')
        {
            header('Content-Type: application/json');
            header('access-Control-Allow-Methods: POST,DELETE,PUT');
            header('access-Control-Max-Age: 3600');
            header('access-Control-Allow-Headers: origin,x-csrftoken,content-Type');
            header('access-Control-Allow-Credentials: true');
            die();
        }else
....
....
....
...
   } else if ($_SERVER['REQUEST_METHOD'] == 'PUT')
                if($action == 'update')
                {
                    $authResp = Auth::autorize($db,isset($_COOKIE['tkn']) ? $_COOKIE['tkn'] : null);
                    if($authResp->getcode() == 200){
                        $roomResp = menu::update($db,$data);
                        $authResp->addToMessage($roomResp->getMessage());
                    }
                    echo $authResp->genResponse();
                    die();                    
                }

要允许PUT / DELETE方法,我还需要设置多少?

SanG_Soul 回答:405方法不允许-PUT(PHP)

问题不在于您的PHP,而在于您的.htaccess;您有<Limit GET POST OPTIONS>限制仅请求 允许GETPOSTOPTIONS。如果您还希望允许PUTDELETE,则需要将它们添加到允许的方法列表中:

<Limit GET POST OPTIONS PUT DELETE>

本文链接:https://www.f2er.com/3163457.html

大家都在问