How to test post method in fiddler - web api
ASP.NET
1
Posts
1
Posters
0
Views
1
Watching
-
I am trying to test my post method using fiddler as below: In the [Composor] tab, I am calling the following url [http://localhost:45361/api/test\], in the [Parse] tab using method type as [POST]. In the [Request Header], I have [User-Agent: Fiddler, Content-Type: application/json; charset=utf-8] and in [Request Body], I am filtering:
{ "name":"storm" }
However, the above post request, returns the entire dataset instead of records with name = storm. I have tried changing the method to [FromBody], which causes reference error in the code:Object reference not set to an instance of an object
[HttpPost]
public HttpResponseMessage post([FromBody] Query query)
{
IQueryable Data = null;if (!string.IsNullOrEmpty(query.tag)) { var ids = query.tag.Split(','); var dataMatchingTags = db.data\_qy.Where(c => ids.Contains(c.TAG)); if (Data == null) Data = dataMatchingTags; else Data = Data.Union(dataMatchingTags); } 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); } 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); }
please advice, if I am missing something or my approach to te