5

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?

3
  • 2
    What is the exact exception message and stack trace? Commented Jul 14, 2011 at 13:50
  • here is stack trace part в System.Convert.FromBase64String(String s) в System.Web.Mvc.ByteArrayModelBinder.BindModel(ControllerContext Commented Jul 14, 2011 at 13:51
  • exception message is localized Commented Jul 14, 2011 at 13:53

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.