How to get hold of Content that is already read

前端 未结 4 1474
小鲜肉
小鲜肉 2020-12-01 06:34

I have a class that inherits from ApiController. It has a Put-method like this:

[PUT(\"user/{UserId}\")]
public HttpResponseMessage Put(string userId, Payme         


        
4条回答
  •  不知归路
    2020-12-01 07:15

    You could read from the underlying request:

    using (var stream = new MemoryStream())
    {
        var context = (HttpContextBase)Request.Properties["MS_HttpContext"];
        context.Request.InputStream.Seek(0, SeekOrigin.Begin);
        context.Request.InputStream.CopyTo(stream);
        string requestBody = Encoding.UTF8.GetString(stream.ToArray());
    }
    

提交回复
热议问题