I'm trying to receive data from an external API that's doing an HTTP POST against my Web API. The content-type of this request is: application/x-www-form-urlencoded. I want the content from this POST request to be saved into my SQL database using Entity Framework. The request is succesful and giving status code 200 but all the values stored into the database are NULL. So I'm wondering how I can map the values from the raw post request to my alerts model.
I have included a screenshot from the POST request using webhook.site below.
AlertsAPI
[HttpPost]
[Consumes("application/x-www-form-urlencoded")]
public async Task<IActionResult> PostAlert([FromForm] Alerts alert)
{
db.Alerts.Add(alert);
await db.SaveChangesAsync();
return CreatedAtAction("Get", new { id = alert.id }, alert);
}
Alerts.cs
public class Alerts
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; }
[FromForm(Name = "sensor")]
public string sensor { get; set; }
[FromForm(Name = "probe")]
public string probe { get; set; }
[FromForm(Name = "group")]
public string group { get; set; }
[FromForm(Name = "device")]
public string device { get; set; }
}
This is the content that im trying to map to my Alert.cs model and save into my database using Entity Framework.
Raw content
Date%2FTime%3A%2005%2F12%2F2020%2020%3A54%3A28%0D%0A%0D%0ATime%20zone%3A%20W.%20Europe%20Standard%20Time%0D%0A%0D%0A=%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0D%0A%0D%0ASensor%3A%20Ping%20%28Ping%29%0D%0A%0D%0APriority%3A%20*****%0D%0A%0D%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0D%0A%0D%0AProbe%3A%20Local%20Probe%0D%0A%0D%0AGroup%3A%20Linux%20%2F%20macOS%20%2F%20Unix%0D%0A%0D%0ADevice%3A%127.0.0.1
