在ASP中发布和读取二进制数据.净MVC
本文关键字:二进制 数据 MVC 读取 ASP | 更新日期: 2023-09-27 18:01:59
我有一个通过HttpWebRequest
发布二进制数据到服务器的问题。下面是我的客户端代码:
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
request.UserAgent = RequestUserAgent;
request.ContentType = "application/x-www-form-urlencoded";
var responseStr = "";
var dataStr = Convert.ToBase64String(data);
var postData = Encoding.UTF8.GetBytes(
string.Format("uploadid={0}&chunknum={1}&data={2}", uploadId, chunkNum, dataStr));
using (var dataStream = request.GetRequestStream())
{
dataStream.Write(postData, 0, postData.Length);
dataStream.Close();
}
然后我想通过MVC控制器的请求工作,这是它的签名:
public ActionResult UploadChunk(Guid? uploadID, int? chunkNum, byte[] data)
但我有错误在这里,说数据不是Base64编码数组,我做错了什么?
您需要通过调用Uri.EscapeDataString
来转义Base64中的+
字符。