Reputation: 2615
I am trying to do a GET request on MVC 4.0 (WebServiceREST) that some method use POST and other use GET but I cant make it works
I used [System.Web.Mvc.AcceptVerbs(HttpVerbs.Get)]
but It didnt work still getting "The requested resource does not support the HTTP 'GET' method"
My Controller:
public class RecuperarDatosAppController : ApiController
{
#region RecuperarClasesColectivas
[System.Web.Mvc.AcceptVerbs(HttpVerbs.Get)]
[ResponseType(typeof(List<ActividadesColectivas>))]
public IHttpActionResult RecuperarClasesColectivas(short idInstalacion, string secretKey = "NOSECRETKEY")
{
BsSecurity bSecurity = new BsSecurity(BsSecurity.Tipo.Publica);
if (bSecurity.comprobar(secretKey))
{
BsActividadesColectivas bsActividades = new BsActividadesColectivas();
return Ok(bsActividades.GetActividadesColectivas(idInstalacion));
}
return NotFound();
}
#endregion
}
Upvotes: 0
Views: 109
Reputation: 32728
Though you state this is MVC and tagged it as such, it's actually Web API, because you're inheriting from ApiController. So you should decorate the method with the [HttpGet]
attribute from the System.Web.Http
namespace. Note that renaming it to have Get
prepended like Yoink is suggesting isn't necessary, although that is the common convention.
Upvotes: 2
Reputation: 780
I believe you need to prepend "Get" to methods that you wish to expose by by GET requests.
So try GetRecuperarClasesColectivas
instead of RecuperarClasesColectivas
.
You'll still call it by /api/RecuperarClasesColectivas/id
for example, the routing just needs the "Get" part adding.
Upvotes: 1