简体   繁体   中英

How Do I Pass Json Object From Fiddler To Webapi2

http://localhost:15641/api/Complaints/NewComplaint

User-Agent: Fiddler

Content-Type: application/json

Host: localhost:15641

Content-Length: 63

RequestBody { "CostCentre":"test","ComplaintText":"This is test Complaint" }

WebApi Controller

[Route("api/Complaints/NewComplaint")]

    [HttpPost]
    public void CreateNewComplaint(BLL.Complaint complaint)
    {
        //call BLL Create complaint method
    }


  }

my object is with null values where am i doing wrong ? i put breakpoints on controller the complaint object is set with all null values if i don't pass the values complaint object it self is null how can i pass the object

Web API expects the data sent to it to be serialized in a fashion like this:

Key1=Value1&Key2=Value2&...

If you are using JavaScript or JQuery, make sure that you're sending an Object(in your case matching Bll.Complaint), not a JSON string. If you give us more details on how you execute the request I will update this answer to have an example of how to do the serialization.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM