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/33056402/

相关文章:

c# - 使 ASP.net GridView 中的列可编辑

asp.net - 如何让 Url.Action 使用正确的端口号?

c# - Google .NET API - 除了 FileDataStore 之外还有其他数据存储吗?

sql - 列 'ID' 被限制为唯一。值(value)已经存在

c# - Process.Start() 继续运行我的 .exe 作为后台进程 MVC ASP.Net

c# - 使用 Entity Framework 6 和 C# 调用现有存储过程

c# - 在 SqlBulkCopy 期间更改值

c# - 使用后台 worker 高效写入 GUI 线程

c# - 将新工作表插入电子表格文档 OpenXml

c# - 如何在MVC中查看PDF文档而不是直接下载?