ASP.NET Core API POST parameter is always null

前端 未结 9 530
自闭症患者
自闭症患者 2020-12-14 00:27

I have read the following:

  • Asp.net Core Post parameter is always null
  • asp.net webapi 2 post parameter is always null
  • web-api POST body object
9条回答
  •  借酒劲吻你
    2020-12-14 01:08

    I needed to post string data by .Net Desktop Client to .NET Core host. I was getting unsupported media error. I have followed Shaun Luttin's answer and worked fine. The I found something easier to get just string data as folows in case someone else finds useful:

    [HttpPost]
    [Route("Request/Echo")]
    public async Task Echo()
    {
        using (var Reader = new StreamReader(Request.Body, Encoding.UTF8))
        {
            return await Reader.ReadToEndAsync();
        }
    }
    

    This post is very useful.

提交回复
热议问题