I would like to change the following api controller method from GET to POST request. I have made the changes on the header however I am getting a the following error, whenever I call api/list?tag=89077&name=prest :
{"$id":"1","Message":"The requested resource does not support http method 'GET'."}
[HttpPost] public HttpResponseMessage Post([FromBody] Query query) { IQueryable<data_qy> Data = null; if (!string.IsNullOrEmpty(query.name)) { var ids = query.name.Split(','); var dataMatchingTags = db.data_qy.Where(c => ids.Any(id => c.Name.Contains(id))); if (Data == null) Data = dataMatchingTags; else Data = Data.Union(dataMatchingTags); } if (Data == null) // If no tags or name is being queried, apply filters to the whole set of products Data = db.data_qy; if (query.endDate != null) { Data = Data.Where(c => c.UploadDate <= query.endDate); } if (query.startDate != null) { Data = Data.Where(c => c.UploadDate >= query.startDate); } Data = Data.OrderByDescending(c => c.UploadDate); var data = Data.ToList(); if (!data.Any()) { var message = string.Format("No data found"); return Request.CreateErrorResponse(HttpStatusCode.NotFound, message); } return Request.CreateResponse(HttpStatusCode.OK, data); }
Do I need to change code in my global.aspx or somewhere else. Please advise.
Many thanks.