How to get POST data in WebAPI?

前端 未结 8 1352
天涯浪人
天涯浪人 2020-11-29 21:32

I\'m sending a request to server in the following form:

http://localhost:12345/api/controller/par1/par2

The request is correctly resolved t

8条回答
  •  时光说笑
    2020-11-29 21:54

    I found for my use case this was much more useful, hopefully it helps someone else that spent time on this answer applying it

    public IDictionary GetBodyPropsList()
            {
                var contentType = Request.Content.Headers.ContentType.MediaType;
                var requestParams = Request.Content.ReadAsStringAsync().Result;
    
                if (contentType == "application/json")
                {
                    return Newtonsoft.Json.JsonConvert.DeserializeObject>(requestParams);
                }
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
    

提交回复
热议问题