I want to make a PUT request to a web api server, using the following.
Angular resource and request:
Books: $resource('/api/book/:id',
{id: '@id'},
{
'update' : {method: 'PUT'}
})
...
$id = book.BookId
BookLibraryAPI.Books.update({id: $id},book);
Web API controller:
public void Put(int id, string book)
{
}
But I get 405 error, with the following headers:
Request URL:http://localhost:53889/api/book/1009
Request Method:PUT
Status Code:405 Method Not Allowed
...
I tried many things, and I still cannot find the issue.
And the entire controller:
[Authorize] public class BookController : ApiController { BusinessBundle _bundle = new BusinessBundle();
// GET api/book
public IEnumerable<Book> Get()
{
return _bundle.BookLogic.GetAll();
}
// GET api/book/5
public Book Get(int id)
{
return _bundle.BookLogic.GetBook(id);
}
// POST api/book
public void Post([FromBody]string value)
{
}
// PUT api/book/5
public void Put(int id, string book)
{
var a = book; // just for testing
}
// DELETE api/values/5
public void Delete(int id)
{
}