我在向我的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方法,我还需要设置多少?