在ASP.NET 5中请求BinaryRead(MVC6)

时间:2022-12-04 18:36:47

I had this code working in ASP.NET MVC 5, but I can't make it works in ASP.NET MVC 6 (ASP.NET 5)

我有这个代码在ASP.NET MVC 5中工作,但我不能使它在ASP.NET MVC 6(ASP.NET 5)中工作

Can someone help me?

有人能帮我吗?

public EmptyResult PayPalPaymentNotification(PayPalCheckoutInfo payPalCheckoutInfo)             {       PayPalListenerModel model = new PayPalListenerModel();                   model._PayPalCheckoutInfo = payPalCheckoutInfo;                     byte[] parameters = Request.BinaryRead(Request.ContentLength);      if (parameters != null)                   {                         model.GetStatus(parameters);                   }      return new EmptyResult();               } 

The error is in:

错误在于:

byte[] parameters = Request.BinaryRead(Request.ContentLength);

HttpRequest does not contain a definition for BinaryRead and no extension method BinaryRead accepting a first argument of type HttpRequest could be found (are you missing a using directive or an assembly reference?).

HttpRequest不包含BinaryRead的定义,也没有扩展方法BinaryRead接受类型为HttpRequest的第一个参数(你是否缺少using指令或程序集引用?)。

I have tested somethings like this, but not working:

我已经测试了这样的事情,但没有工作:

HttpContext.Request.BinaryRead

Thanks.

Edit: Similar quesiton -> Error in binary read

编辑:类似问题 - >二进制读取错误

1 个解决方案

#1


4  

The HttpRequestFeature object now provides a body which is a stream. So this should work.

HttpRequestFeature对象现在提供一个作为流的主体。所以这应该工作。

    public static byte[] ReadRequestBody(Stream input)    {        using (MemoryStream ms = new MemoryStream())        {            input.CopyTo(ms);            return ms.ToArray();        }    }

and then ...

接着 ...

 var paramArray = ReadRequestBody(Request.Body);

#1


4  

The HttpRequestFeature object now provides a body which is a stream. So this should work.

HttpRequestFeature对象现在提供一个作为流的主体。所以这应该工作。

    public static byte[] ReadRequestBody(Stream input)    {        using (MemoryStream ms = new MemoryStream())        {            input.CopyTo(ms);            return ms.ToArray();        }    }

and then ...

接着 ...

 var paramArray = ReadRequestBody(Request.Body);