在ASP.NET 5(MVC6)中请求BinaryRead [英] Request BinaryRead in ASP.NET 5 (MVC6)
问题描述
我有这段代码可以在ASP.NET MVC 5中运行,但是我无法使其在ASP.NET MVC 6(ASP.NET 5)中运行
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)
有人可以帮助我吗?
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不包含BinaryRead的定义,并且没有 扩展方法BinaryRead接受类型的第一个参数 可以找到HttpRequest(您是否缺少using指令或 程序集参考?).
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
谢谢.
类似的问题-> 二进制读取错误
推荐答案
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();
}
}
然后...
var paramArray = ReadRequestBody(Request.Body);
这篇关于在ASP.NET 5(MVC6)中请求BinaryRead的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!