php-crud-api icon indicating copy to clipboard operation
php-crud-api copied to clipboard

Cannot use DELETE OR PUT (400 BadRequest)

Open jahu opened this issue 10 years ago • 5 comments

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?

jahu avatar Dec 14 '15 08:12 jahu

The same happens with PUT request.

jahu avatar Dec 14 '15 09:12 jahu

Don't send a body on a DELETE. What is the PUT you are trying to execute?

mevdschee avatar Dec 14 '15 11:12 mevdschee

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).

mevdschee avatar Dec 14 '15 11:12 mevdschee

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.

jahu avatar Dec 14 '15 13:12 jahu

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.

mevdschee avatar Dec 15 '15 12:12 mevdschee