I have a route with this route
/**
* @Method({"DELETE"})
* @Route("/secure/users")
*/
When I try to do a cUrl
<html>
<head>
<meta charset="UTF-8" />
<title>An Error Occurred: Method Not Allowed</title>
</head>
<body>
<h1>Oops! An Error Occurred</h1>
<h2>The server returned a "405 Method Not Allowed".</h2>
<div>
Something is broken. Please let us know what you were doing when this error occurred.
We will fix it as soon as possible. Sorry for any inconvenience caused.
</div>
</body>
</html>
I tried to enable also
Request::enableHttpMethodParameterOverride();
in app.dev and app_dev.php, infact I can handle the PUT
requests.
Add this parameter to your curl request :
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
or in command line
curl -X DELETE "http://localhost/secure/users"
If you are performing an XHR request using jQuery, just do
$.ajax({
url: '/secure/users',
type: 'DELETE',
data: { id: resourceToDelete }
success: function(result) {
// Do something with the result
}
});
And for pure javascript :
var req = new XMLHttpRequest();
req.open('DELETE', '/secure/users');
req.setRequestHeader("Content-type", "application/json");
req.send({ id: 'entityIdentifier' });
If you want access it by browser or pass query params like /secure/users?id=x
, use GET :
/**
* @Method({"GET"})
* @Route("/secure/users")
*/
See What is the usefulness of PUT and DELETE HTTP request methods?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With