Request BinaryRead in ASP.NET 5 (MVC6)

我的未来我决定 提交于 2019-12-10 23:37:10

问题


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)

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?).

I have tested somethings like this, but not working:

HttpContext.Request.BinaryRead

Thanks.

Edit: Similar quesiton -> Error in binary read


回答1:


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

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

and then ...

 var paramArray = ReadRequestBody(Request.Body);


来源:https://stackoverflow.com/questions/33056402/error-in-binary-read

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!