Can you check to ensure that the HttpPut attribute that you are referencing is coming from System.Web.Http or you can consider using a
workaround like the one mentioned here which involves using the [PUT] attribute along with the route :
[PUT("some/url"), HttpPut]
public string Method2() {}
Error 2 'ContactManager.Controllers.ContactController.PUT(int, ContactManager.Models.Contact)' is a 'method' but is used like a 'type' C:\Users\stula1289\Documents\Visual Studio 2013\Projects\ContactManager\ContactManager\Controllers\ContactController.cs
72 10 ContactManager
Your controller action method expects parameter id in the url. Also it is good practice to add [FromBody] for contact parameter like this
[HttpPatch]
[HttpPut]
public HttpResponseMessage PUT(int id,[FromBody]Contact contact)
{
contact.ID = id;
if(!contactRepository.Update(contact))
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return Request.CreateResponse(HttpStatusCode.OK);
}
Now try to access Web Api with following code
using (var client = new HttpClient())
{
// Create object of Contact and set properties
Contact contact = new Contact () ;
client.BaseAddress = new Uri("http://localhost:58745/");
var response = client.PutAsJsonAsync("api/ControllerName/10", contact).Result;
if (response.IsSuccessStatusCode)
{
string responseString = response.Content.ReadAsStringAsync().Result;
}
}
None
0 Points
12 Posts
PUT method not supported
Aug 27, 2015 11:40 AM|sumittuladhar|LINK
I am trying to test my Rest Web API through postman. I got the error
"Message": "The requested resource does not support http method 'PUT'."
I have define Put method in my controller. Why am I getting this error?
"Message": "The requested resource does not support http method 'PUT'."
api Web mvc
All-Star
114593 Points
18503 Posts
MVP
Re: PUT method not supported
Aug 27, 2015 01:11 PM|Rion Williams|LINK
Can you check to ensure that the HttpPut attribute that you are referencing is coming from System.Web.Http or you can consider using a workaround like the one mentioned here which involves using the [PUT] attribute along with the route :
api Web mvc
None
0 Points
12 Posts
Re: PUT method not supported
Aug 27, 2015 04:28 PM|sumittuladhar|LINK
It gave me this error.
Error 2 'ContactManager.Controllers.ContactController.PUT(int, ContactManager.Models.Contact)' is a 'method' but is used like a 'type' C:\Users\stula1289\Documents\Visual Studio 2013\Projects\ContactManager\ContactManager\Controllers\ContactController.cs 72 10 ContactManager
api Web mvc
Star
9859 Points
974 Posts
Re: PUT method not supported
Aug 28, 2015 01:42 AM|Li Wang|LINK
Hi sumittuladhar,
Did you register route when application start?
Best Regards,
Wang Li
api Web mvc
None
0 Points
12 Posts
Re: PUT method not supported
Aug 28, 2015 10:52 AM|sumittuladhar|LINK
Yes I did. All the other method like get,post,delete are working except for PUT method. I don't know whats wrong there.
api Web mvc
Contributor
2290 Points
493 Posts
Re: PUT method not supported
Aug 28, 2015 09:56 PM|santhoshje|LINK
Your controller action method expects parameter id in the url. Also it is good practice to add [FromBody] for contact parameter like this
Now try to access Web Api with following code
api Web mvc