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

标签 c# asp.net asp.net-mvc asp.net-core asp.net-core-mvc

我让这段代码在 ASP.NET MVC 5 中工作,但我无法让它在 ASP.NET MVC 6 (ASP.NET 5) 中工作

有人可以帮助我吗?

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();           
    } 

错误在:

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

我已经测试过类似的东西,但没有用:

HttpContext.Request.BinaryRead

谢谢。

编辑:类似问题 -> Error in binary read

最佳答案

HttpRequestFeature 对象现在提供一个 body which is a stream .所以这应该有效。

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

然后……

 var paramArray = ReadRequestBody(Request.Body);

关于c# - 在 ASP.NET 5 (MVC6) 中请求 BinaryRead,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35553515/

相关文章:

c# - 奇怪的是 SQL Server Management Studio 中的数据

c# - 如何在 TableLayoutPanel 中对齐文本框和标签?

c# - 如何使用 Entity Framework 更新数据库而无需迁移历史记录

c# - 如何从alertbox获取OK和CANCEL的值

c# - 如何从gridview页脚C#中的文本框中获取值?

asp.net-mvc - ASP.NET MVC : Good Replacement for User Control?

asp.net - 从 User.Identity.Name 中删除域名

c# - 如何覆盖视频的 i 帧?

asp.net - 更新表单后保持对 ajax 更新面板的关注

asp.net-mvc - Microsoft Graph API 向任何请求返回 403