Post and read binary data in ASP.NET MVC

允我心安 提交于 2019-12-07 07:41:45

问题


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();
}

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)

But I have error here, saying that data is not Base64 coded array, what am I doing wrong?


回答1:


You need to escape the + characters in your Base64 by calling Uri.EscapeDataString.



来源:https://stackoverflow.com/questions/6694185/post-and-read-binary-data-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!