0
I have a SPA application and it consumes a REST API made in ASP.NET Webapi.
When trying to accomplish a Insert in the API, the following error is returned:
Response for preflight has invalid HTTP status code 405
In the web.config
of the Webapi I set up like this:
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, PUT, POST, DELETE, OPTIONS" />
</customHeaders>
I don’t know why it happens.
Angular:
$scope.inserirCarro = function () {
var carro = {
CarroNome: $scope.nome,
MinCod: $scope.selectMin
};
var carroData = crudService.IncluirCarro(carro);
carroData.then(function (data) {
getCarros();
if (data.status == 200) {
toastr["success"]("Registro cadastrado com sucesso!", "Sistema");
}
}, function () {
toastr["error"]("Erro ao incluir!", "Sistema");
});
}
Service at the angle:
this.IncluirCarro = function (carro) {
var response = $http({
method: "post",
url: urlAPI + "/api/v1/carros/postcarro",
data: JSON.stringify(carro),
dataType: "json"
});
return response;
}
1. Do you have any method that is already working? 2. When testing by some helper like Postman or Fiddler this method works normal? 3. Are you using Owin?
– Jéf Bueno
Yes, the data return method is working. I haven’t tested for any helper yet. I’m not using Owin
– novato
Post your Webapi controller code.
– Jéf Bueno
I found the problem... have to install the CORS
– novato