0

I send GET request to .NET Web API application from Angular but I got 405 error.

When I send same request to same address on POSTMAN, everythings looks correctly.

My api codes

public IHttpActionResult GetUsers()
{
    response.error = false;
    response.data = db.Users;
    response.message = result.message;
    return Ok(response);
}

And my Angular codes are below

service.getCategories = function (callback) {

    var url = $rootScope.servicePath + "/categories";

    $http({
        method: 'GET',
        url: url
    })
        .then(function successCallback(response) {
            callback(response.data)
        });

};

Result of request:

enter image description here

Furkan Başaran
  • 1,794
  • 2
  • 15
  • 26
  • Possible duplicate of [AngularJS performs an OPTIONS HTTP request for a cross-origin resource](http://stackoverflow.com/questions/12111936/angularjs-performs-an-options-http-request-for-a-cross-origin-resource) – Martijn Welker Feb 23 '16 at 10:33

1 Answers1

0

When I added this line to head of my controller

[EnableCors(origins: "*", headers: "*", methods: "*")]

Problem solved.

Furkan Başaran
  • 1,794
  • 2
  • 15
  • 26