[mono-android] System.Net.WebClient.UploadFileAsync Problem
Gonzalo Paniagua Javier
gonzalo.mono at gmail.com
Thu Jan 19 16:39:39 UTC 2012
On Thu, Jan 19, 2012 at 11:10 AM, Gonzalo Paniagua Javier
<gonzalo.mono at gmail.com> wrote:
> On Thu, Jan 19, 2012 at 10:57 AM, subsembly <a.selle at subsembly.com> wrote:
>> It's not a feature request. It's a SEVERE BUG in the Mono WebClient
>> implementation!
>
> Ok. Since the world is going to end, I will take a look just to make
> sure that it is just a common bug and can be fixed quickly ;-).
Turns out the world is not going to end today. This is not a bug.
The following program:
---------------
using System;
using System.Net;
using System.Threading;
class Test {
static void Main ()
{
ManualResetEvent evt = new ManualResetEvent (false);
WebClient wc = new WebClient ();
wc.UploadFileCompleted += new UploadFileCompletedEventHandler (CB);
wc.UploadFileAsync (new Uri ("http://127.0.0.1:9000/"), "POST",
"uploadfile.cs", evt);
evt.WaitOne ();
}
static void CB (object sender, UploadFileCompletedEventArgs e)
{
if (!e.Cancelled && e.Error == null) {
Console.WriteLine ("File uploaded");
} else {
Console.WriteLine ("Something went wrong");
Console.WriteLine (e.Error);
}
((ManualResetEvent) e.UserState).Set ();
}
}
--------------
when run under MS.NET has this at the beginning of the body:
-----------------------8cea4b4aff65c6b
Content-Disposition: form-data; name="file"; filename="uploadfile.cs"
Content-Type: application/octet-stream
The same program run using Mono yields:
--------------8cea4b552ea3188
Content-Disposition: form-data; name="file"; filename="uploadfile.cs"
Content-Type: application/octet-stream
Perhaps what you want is more like:
file.ReadAllBytes ("yourfile");
wc.UploadData (...).
Cheers.
-Gonzalo
More information about the Monodroid
mailing list