Cannot use DELETE OR PUT (400 BadRequest)
I'm wondering why I recieve following result when trying DELETE request on some enttiy:
<HTML>
<HEAD>
<TITLE>400 Bad Request</TITLE>
</HEAD>
<BODY BGCOLOR=#FFFFFF>
<H1>400 Bad Request</H1>
Your browser sent a request that this server could not understand.
</BODY>
</HTML>
I am trying to use the api from within angularJs controller as well as Postman - same result.
My request is following:
var req = {
method: 'DELETE',
url: 'http://some.application.com/api/api.php/registration/' + $scope.registrationToBeDeleted,
data: {
},
headers: {
'Content-Type': 'application/json'
}
};
$http(req).success(function(data){
$scope.checkTodayReservations();
});
I've tried to remove headers and data elements - same result.
Could you please help?
The same happens with PUT request.
Don't send a body on a DELETE. What is the PUT you are trying to execute?
I don't think the script ever sends a 400:
$ grep header api.php
header('Content-Type:',true,404);
header('Content-Type:',true,403);
header('Content-Type:',true,409);
header('Content-Type:',true,422);
So, this must have been sent by your web browser (Apache, IIS, nginx).
I am wondering whether it is not related to my hosting policy. I've tried to use DELETE without payload, the same result. In PUT I've just entered fields I wanted to update in json (+ content type json in request header).
I've overcome this with custom php script for data deletion and update (I need it working now), however I will come back to this issue whenever I will have some spare time.
Sure, but without any context of your hosting environment it is hard for me to help you. I think you are running IIS, based on your output. In "IIS Manager" go to "Handler Mappings" and click "Edit" on the ".php" handler. Then go to "Request Restrictions" and the "Verbs" tab. Now select the "All verbs" option to allow all verbs.