在ASP.NET MVC发布和阅读的二进制数据 [英] Post and read binary data in ASP.NET MVC
本文介绍了在ASP.NET MVC发布和阅读的二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经通过的HttpWebRequest
二进制数据到服务器的发布有问题。这里是我的客户code:
I have a problem with posting of binary data to server via HttpWebRequest
. Here is my client code:
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控制器要求的工作,这里是它的签名:
And then I want to work with request via MVC controller, here is it's signature:
public ActionResult UploadChunk(Guid? uploadID, int? chunkNum, byte[] data)
但我有错误,则说数据不是Base64的codeD阵,我究竟做错了什么?
But I have error here, saying that data is not Base64 coded array, what am I doing wrong?
推荐答案
您需要通过调用乌里逃避你的Base64编码的
。 +
字符。 EscapeDataString
You need to escape the +
characters in your Base64 by calling Uri.EscapeDataString
.
这篇关于在ASP.NET MVC发布和阅读的二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文