Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core HttpRequest class has no BinaryRead method

Tags:

c#

asp.net

I am working on an ASP.NET Core app, however they don't seem to have ported the entire HttpRequest class into Microsoft.AspNetCore.Mvc. This method is missing:

https://msdn.microsoft.com/en-us/library/system.web.httprequest.binaryread(v=vs.90).aspx

Is there another way to do the same thing? I don't see a similar method to replace it.

like image 358
ulak blade Avatar asked Feb 25 '26 14:02

ulak blade


1 Answers

You can use a MemoryStream on the Request and retrieve the content of the Body.

Something like:

using (var ms = new MemoryStream(2048))
{
    await Request.Body.CopyToAsync(ms);
    var rawData = ms.ToArray();  
}
like image 88
d.moncada Avatar answered Feb 27 '26 04:02

d.moncada