Bug 10163 - System.Net.WebClient.OpenWrite not working
Summary: System.Net.WebClient.OpenWrite not working
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 3.0.x
Hardware: Other Linux
: High major
Target Milestone: Untriaged
Assignee: Martin Baulig
Depends on:
Reported: 2013-02-08 08:17 UTC by Philipp
Modified: 2014-08-25 12:15 UTC (History)
6 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Philipp 2013-02-08 08:17:37 UTC
I use the following code:

            System.Net.WebClient webClient = new System.Net.WebClient();
            string webAddress = "https://sd2dav.1und1.de/"; //1&1 Webdav
            string destinationFilePath = webAddress + "testfile.txt";
            webClient.Credentials = new System.Net.NetworkCredential("myuser", "mypassword");
            Stream stream = webClient.OpenWrite(destinationFilePath,"PUT");

            UnicodeEncoding uniEncoding = new UnicodeEncoding();

            using(StreamWriter sw = new StreamWriter(stream, uniEncoding))

This works fine when compiled with Visual Studio 2008, .net 3.5 and executed on Windows 7. However, I would like to do this with Mono for Android (4.4.54). Here, the code executes, but nothing happens: The file is not created on the server.
Comment 1 Daniel Schaal 2013-05-10 13:32:37 UTC
Using the same code this also happens on Linux using mono 3.0.6 (Debian packages).

This used to work with the previous version in Debian, which was

This also breaks Keepass2 when trying to save to Webdav (also see https://sourceforge.net/p/keepass/bugs/1117/).
Comment 3 Martin Baulig 2014-08-11 09:50:35 UTC
The sync API is working perfectly fine; the async one needs a small fix that I already have a patch for.

However, there's another issue with OpenWrite(): we need to wait for and actually read the response from the server when closing the stream.  This does not seem to happen yet.
Comment 4 Martin Baulig 2014-08-25 12:15:34 UTC

Note that WebClient.OpenWriteAsync() and WebClient.OpenWriteTaskAsync() is not actually "async" - these APIs should be avoided in async applications.