Search code examples
jsonasp.net-mvcasp.net-web-apifiddler

How to pass multiple json value for post method using fiddler


I'm new with web api and fiddler as well as json, i want to test my api with fiddler. In this image i've recieved the requested data In this image i've recieved the requested data

and I've returned Json data to mobile device but now when i want to test it through fiddler web debugger

fiddler

it shows "HTTP/1.1 404 Not Found" in fiddler Headers tab


Solution

  • What you need is a method that takes as a parameter the object sent as JSON. WebApi will handle the deserialization for you.

    Something like this on server side would work:

    public class BooksController : ApiController
    {
        [HttpPost]
        public void Post([FromBody]Book book)
        {
            // do someting with book here...
        }
    }
    
    public class Book
    {
        public string OfficeCode { get; set; }
        public string BookNo { get; set; }
        public string MeterNo { get; set; }
        public string AccountNo { get; set; }
    }
    

    From the client, the body should look like

    {
       "OfficeCode": "string",
       "BookNo": "string",
       "MeterNo": "string",
       "AccountNo": "string"
    }