开发者

Post and read binary data in ASP.NET MVC

开发者 https://www.devze.com 2023-03-20 02:42 出处:网络
I have a problem with posting of binary data to server via HttpWebRequest. Here is my client code: var request = (HttpWebRequest)WebRequest.Create(uri);

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, he开发者_开发百科re 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号