Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to test post method in fiddler - web api

How to test post method in fiddler - web api

Scheduled Pinned Locked Moved ASP.NET
databasejsonlinqagentic-aihelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    miss786
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups