[英]WebApi NET Core not receiving request json, whereas it does in NET standard
I created a NET Core starter WebApi project and added a very simple method/object.我创建了一个 NET Core 入门 WebApi 项目并添加了一个非常简单的方法/对象。 Testing the endpoint with Fiddler the request body doesnt bind to the post param.
使用 Fiddler 测试端点,请求正文不会绑定到 post 参数。 I had spent 2 hours of searching for a solution to no avail.
我花了 2 个小时寻找解决方案无济于事。 For brevity I included my object in the controller.
为简洁起见,我将 object 包含在 controller 中。
namespace CoreWebApi.Controllers
{
using Microsoft.AspNetCore.Mvc;
[Route("[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
[HttpPost]
public Message Post([FromBody]Message message)
{
return message;
}
}
public class Message
{
public string Application;
public string StatusOverride;
}
}
After a lot of head scratching, I created a NET Standard web api starter project, copy/paste of my method and object and worked first time.经过一番摸索,我创建了一个 NET Standard web api 入门项目,复制/粘贴我的方法和 object 并第一次工作。 Wondering if someone can enlighten me as to what I would need to do on my NET core webapi to get it working.
想知道是否有人可以告诉我我需要在我的 NET 核心 webapi 上做什么才能使其正常工作。
using System.Web.Http;
namespace WebApplication9.Controllers
{
public class ValuesController : ApiController
{
public Message Post([FromBody]Message message)
{
return message;
}
}
public class Message
{
public string Application;
public string StatusOverride;
}
}
Even though class members are public, they still need to have get/set accessors:即使 class 成员是公共的,他们仍然需要有 get/set 访问器:
public class Message
{
public string Application { get; set; }
public string StatusOverride { get; set; }
}
...and it works! ......它的工作原理!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.