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
Make a File Open in Browser Instead of Downloading It
Casting an Object into the Same Type as an Ienumerable Collection
How to Return a File (Filecontentresult) in ASP.NET Webapi
How to Asynchronously Wait for X Seconds and Execute Something Then
How to Make a Soap/Wsdl Client in C#
How to Convert a List to Ienumerable
How to Download Image from Url
How to Use Variable in Feature File
How to Upload File to Server With Http Post Multipart/Form-Data
How to Disable Uwp App Suspension
How to Calculate Sum (Total) of Datatable Columns Using C#
How to Dynamically Adjust Table Column Width in Rdlc Report
Cannot Access a Closed Stream of a Memorystream, How to Reopen
How to Call a Button Click Event from Another Method
Returning a File to View/Download in ASP.NET MVC
C# SQL Server Stored Procedure Parameter Return List
How to Determine Browser Window Size on Server Side C#
How to Download File With ASP.NET on Buttton'S Onclick Event