I'm getting a 404 error with a PUT request when using AngularJS's "$http.put".
Here is my relevant AngularJS code:
/* toggles whether or not the link is disabled */
toggleLinkStatus: function (isActive, linkGUID) {
$http.put('/Explorer/Link/ToggleLinkStatus',
{
isActive: isActive,
linkGUID: linkGUID
}
);
}
And my relevant C# Controller Code:
[HttpPut]
public IHttpActionResult ToggleLinkStatus(Boolean isActive, Guid linkGUID)
{
return Ok();
}
And my WebApiConfig Code
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
/** define routes for Explorer API */
config.Routes.MapHttpRoute(
name: "ExplorerAPI",
routeTemplate: "Explorer/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
What am I missing here? In the Headers for the call I can see that the data is being passed through in the Request Payload:
isActive: true
linkGUID: "b94badb3-2917-4129-9ae3-35d2a635f66d"
If I do a normal query string PUT using POSTMAN it goes through, but not when I use AngularJS.
UPDATE
Here's something interesting, if I use the following angularJS request it goes through:
/* toggles whether or not the link is disabled */
toggleLinkStatus: function (isActive, linkGUID) {
$http.put('/Explorer/Link/ToggleLinkStatus',
{
isActive: isActive,
linkGUID: linkGUID
},
{
params:
{
isActive: isActive,
linkGUID: linkGUID
}
}
);
}
It also works with this:
/* toggles whether or not the link is disabled */
toggleLinkStatus: function (isActive, linkGUID) {
$http.put('/Explorer/Link/ToggleLinkStatus',
{
},
{
params:
{
isActive: isActive,
linkGUID: linkGUID
}
}
);
}