Web-Api Post Body Object Always Null

Why is my form body always null in Web API?

in postman, set the "content-type" as JSON (application/json)

C# Web API POST parameter FromBody is always null

Your json object is invalid. My suggestion is to always run json object written manually through a json parser like this: http://json.parser.online.fr/

"Tijd":{"09-08-2016 9:25"}

should instead be

"Tijd":["09-08-2016 9:25"]

Web API post array but frombody is always null

Your JSON is an array of arrays. The method is expecting an array of objects which match the format of the AddServer class.

Your JSON should look something like this:

[
{
"HostName": "Server1",
"Type1": "type1_1",
"Type2": "type1_1",
},
{
"HostName": "Server2",
"Type1": "type1_2",
"Type2": "type2_2",
}
]

Change to function

This has required some guesswork as I don't know the service contract which is feeding into the function but what needs to be changed is in the loop.

for ( let i = 0; i < allTextLines.length; i++) {
// split content based on comma
let data = allTextLines[i].split(',');

if (data.length == headers.length) {
let tobj = {};

tobj.HostName = data[0];
tobj.Type1= data[1];
tobj.Type2= data[2];

lines.push(tobj);
}
}


Related Topics



Leave a reply



Submit