1
votes

i have developed a front end to a RESTAPI using angularjs when i try to write a DELETE using $resource it will give me following error

Method DELETE is not allowed by Access-Control-Allow-Methods.

2
So...does the server you're trying to connect to support DELETE? - Makoto
@Makoto yes it is supporting to DELETE. when i used google advanced rest client and send the same API call through that it works fine. - madu
Is the REST API public ? If so, could you provide it for testing? - Chickenrice

2 Answers

0
votes

I am also doing the something with angular but I hope this may help you. Here is a solution: First have to update in your API web.config file

<clear />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
<add name="Access-Control-Allow-Methods" value="OPTIONS,GET,POST,PUT,DELETE" />

In `ApiController`

[HttpDelete]
public string Delete() 
{ 
return "u call delete"; 
} 

public HttpResponseMessage Options() { 
     var response = new HttpResponseMessage(); 
     response.StatusCode = HttpStatusCode.OK; 
return response; 
}


In Angular...

        home.post().then(function (data) {
            console.log(data);
        });

        home.remove().then(function (data) {
            console.log(data);
        });

Out Put...

> u call delete

Hope this will help you.. :)
-1
votes

you cant access DELETE because its not allow from the server, so: 1. you could change that when you are the owner of the restapi 2. look in the docs of the the API for more information, how to arrive your goal

here is a nice posts to this tobic