Я пытаюсь получить JSON из тела, но всегда получаю ноль.
Это мой код в MVC
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Mvc;
using System.Web.Http;
using System.Net.Http;
using System.Net;
using System.IO;
namespace WebApplication5.Controllers
{
public class NimsoftController : Controller
{
static readonly Dictionary<Guid, Alert> alerts = new Dictionary<Guid, Alert>();
// GET: Nimsoft
//public ActionResult CreateAlarm()
[System.Web.Mvc.HttpPost]
public HttpResponseMessage CreateAlarm([FromBody] Alert val)
{
Models.CreateAlarm CreateAlarm = new Models.CreateAlarm();
System.IO.File.AppendAllText(@"D:\log.txt", string.Join(",", val.message));
string jsonAlarm = new JavaScriptSerializer().Serialize(new
{
message = "Test Message"//string.Join(",",alert.alerts),
});
var response = new HttpResponseMessage(HttpStatusCode.Created)
{
Content = new StringContent(jsonAlarm)
};
return response;
}
}
}
и мой запрос
User-Agent: Fiddler
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-type: application/x-www-form-urlencoded
Host: localhost:52151
Content-Length: 27 '