接收byte []作为参数 - MVC [英] Receive byte[] as parameter - MVC

查看:62
本文介绍了接收byte []作为参数 - MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



1.服务器端:我有一个方法打算从WebClient.UploadData接收byte [],但我似乎无法实现这个。

2.我尝试了以下内容:

- System.IO.Stream导致错误无法创建抽象类。

- System.IO.MemoryStrem导致错误此流不支持超时。

- byte [] - 输入参数为null。

- 谷歌,它带我进入圈子:(



客户端代码:使用WebClient.UploadData发布数据

  byte  [] _data = Encoding.UTF8.GetBytes(parameters); 
byte [] _result = client.UploadData(_URL,_data); // client:System.Net.WebClient





服务器端:尝试接收WebClient.UploadData发布的数据

  public   byte  [] Receive_Data(流数据)< span class =code-comment> //   System.IO.Stream  
{
...
}

public byte [] Receive_Data(MemoryStream数据) // System.IO.MemoryStrem
{
...
}

public byte [] Receive_Data( byte [] data) // byte []
{
...
}





我不确定我做错了什么,请有人指出我在右边方向/替代。所有反馈都非常受欢迎。



注意:这是在MVC

  public   HomeController:Controller 

解决方案

此HTTP侦听器可能有所帮助。



https://msdn.microsoft.com/en-us/library/system.net.httplistener.begingetcontext(v = vs.110).aspx [ ^ ]

Hi All

1. Server-side: I have a method that intends on receiving the byte[] from WebClient.UploadData but I can not seem to achieve this.
2. I have tried the following:
- System.IO.Stream which results in an error "Cannot create an abstract class".
- System.IO.MemoryStrem which results in an error "Timeouts are not supported on this stream".
- byte[] - The input parameter is null.
- Google, which took me in circles :(

Client-side code: Posting data using WebClient.UploadData

byte[] _data = Encoding.UTF8.GetBytes(parameters);
byte[] _result = client.UploadData(_URL, _data); // client: System.Net.WebClient



Server-side: Attempting to receive the data posted by WebClient.UploadData

public byte[] Receive_Data(Stream data) // System.IO.Stream
{
 ...
}

public byte[] Receive_Data(MemoryStream data) // System.IO.MemoryStrem
{
 ...
}

public byte[] Receive_Data(byte[] data) // byte[]
{
 ...
}



I'm not sure what I doing wrong, please could someone point me in the right direction/alternative. All feedback is highly appreciated.

Notes: This being done in MVC

public class HomeController : Controller

解决方案

This HTTP Listener might help.

https://msdn.microsoft.com/en-us/library/system.net.httplistener.begingetcontext(v=vs.110).aspx[^]


这篇关于接收byte []作为参数 - MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆