C#’s uploadData method doesn’t encode the data that is being sent. So, if I send a file over (after converting it into bytes) using this method, and the receiving side is looking for a multiform/form-data post, then it will obviously not work. Will adding a header like :
WebClient c = new WebClient();
c.Headers.Add("Content-Type", "multipart/form-data");
make it send the data encrypted as multiform, or will the data be still not encrypted (and hence unparseable by servers expecting multiform data) ?
Note that I can’t use WebClient's uploadFile, as I don’t have permission to get the file path location on the client side (I just have a stream, that I can convert to bytes)
Why don’t you use
UploadFileof WebClient over https if you want it to be secure? and that will automatically take care of addingmultipart/form-data.Example using
UploadFilehttp://msdn.microsoft.com/en-us/library/36s52zhs.aspx
And one more thing, encoding and encrypting are 2 different things.
Edit:
You should probably tag your question as Silverlight if you you are using WebClient in your WebClient project. Anyways, WebClient class in SL doesn’t have any UploadData method. See this for more info:
http://msdn.microsoft.com/en-us/library/system.net.webclient%28v=vs.95%29.aspx
Anyways, here is the working solution to your problem:
In your button click, have this code:
and the event itself:
where _boundaryNo is
private string _boundaryNo = DateTime.Now.Ticks.ToString("x");I had it working with Asp.Net MVC 4 and Silverlight 5.
Good luck 🙂