我有一个web api方法,如下所示:
[HttpPost]
[Route("message")]
public IHttpActionResult Post(IEnumerable<Email> email)
{
return Ok("message sent");
}
使用Fiddler,我发送的请求如下:
User-Agent: Fiddler
Host: localhost:3994
Content-Length: 205
Content-Type: application/json; charset=utf-8
{
"To": "someone@emailaddress.com",
"From": "Tom",
"Body": "Cruise",
"Template":"template"
}
我的电子邮件课程如下所示:
public class Email
{
public string Body { get; set; }
public string From { get; set; }
public string To { get; set; }
public string Template { get; set; }
它击中了我的API方法,但它返回了null。我一直在谷歌搜索并尝试json请求的所有不同变体,例如:
{
"email":
{
"To": "someone@emailaddress",
"From": "Tom",
"Body": "Cruise",
"Template": "template"
}
}
以及许多其他方式,但每次电子邮件参数都以null形式出现。我究竟做错了什么?