how to post plain text to ASP.NET Web API endpoint?

前端 未结 6 2230
时光取名叫无心
时光取名叫无心 2020-12-04 17:34

I have an ASP.NET Web API endpoint with controller action defined as follows :

[HttpPost]
public HttpResponseMessage Post([FromBody] object text)

6条回答
  •  悲&欢浪女
    2020-12-04 18:16

    In ASP.NET Core 2.0 you simply do the following :-

    using (var reader = new StreamReader(Request.Body))
    {
          string plainText= reader.ReadToEnd();
    
          // Do something else
    
          return Ok(plainText);
    }
    

提交回复
热议问题