Getting the raw Request in ASP.NET MVC

前端 未结 2 1562
-上瘾入骨i
-上瘾入骨i 2021-01-03 20:09

I need to get the raw request string. Below is an example of the http request sent to the Controller. Actually, I need Post data (last line). How can I get that?

Not

2条回答
  •  感动是毒
    2021-01-03 21:11

    @louis-ricci answear is correct, but bear in mind that if you use [FromBody] in your Action Method, you'll get exception when calling Request.InputStream, since [FromBody] already reads the request body in order to serialize to the model by invoking HttpRequest.GetBufferlessInputStream(), and this method can't be invoked twice. To get around this, simply don't use [FromBody] in your request and serialize the raw request string manually to your model.

    Edit: For better context and search results on this topic, the error thrown has this message:

    This method or property is not supported after HttpRequest.GetBufferlessInputStream has been invoked
    

提交回复
热议问题