I have an oData controller in my Web API 2 solution and I an trying to call the Delete action from my angularJs app. I have tried:
$http({
method: 'DELETE',
url: "http://localhost:52389/odata/Bears('" + $scope.itemKey + "')",
headers: { 'Content-Type': 'application/json' }
}).then(function successCallback(response) {
console.log('success', response);
}, function errorCallback(response) {
console.log('error', response);
});
In fiddler this seems to send an OPTIONS request to the API. Inspecting the sent request in fiddler, I can see that this is what is sent:
OPTIONS http://localhost:52389/odata/Bears('1') HTTP/1.1
Host: localhost:52389
Connection: keep-alive
Access-Control-Request-Method: DELETE
Origin: http://localhost
X-FirePHP-Version: 0.0.6
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36
Access-Control-Request-Headers: accept
Accept: */*
Referer: http://localhost/?id=places
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
If I change, in fiddler, the first line from:
OPTIONS http://localhost:52389/odata/Bears('1') HTTP/1.1
to:
DELETE http://localhost:52389/odata/Bears('1') HTTP/1.1
Then this works. How do I get the method to be 'DELETE' from angularJs?