POST string to ASP.NET Web Api application - returns null

前端 未结 7 1651
有刺的猬
有刺的猬 2020-11-28 08:05

Im trying to transmit a string from client to ASP.NET MVC4 application.

But I can not receive the string, either it is null or the post method can not be found (404

7条回答
  •  猫巷女王i
    2020-11-28 08:43

    For WebAPI, here is the code to retrieve body text without going through their special [FromBody] binding.

    public class YourController : ApiController
    {
        [HttpPost]
        public HttpResponseMessage Post()
        {
            string bodyText = this.Request.Content.ReadAsStringAsync().Result;
            //more code here...
        }
    }
    

提交回复
热议问题