2

我想将数据写入服务器上的文件。因此,我使用以下代码:

            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))
            {
                sw.Write("text");
                sw.Flush();
            }

            webClient.Dispose();

这在使用 Visual Studio 2008、.net 3.5 编译并在 Windows 7 上执行时工作正常。但是,我想使用 Mono for Android (4.4.54) 来执行此操作。在这里,代码执行,但没有任何反应:文件未在服务器上创建。

这是 Mono for Android 中的错误还是上面的代码有什么问题?你知道让这个工作的方法吗?

更新:我在https://bugzilla.xamarin.com/show_bug.cgi?id=10163提交了关于此问题的错误。希望来自 Xamarin 的人能解决这个问题。此外,我在https://stackoverflow.com/questions/14786214/alternative-to-webclient-openwrite提出了另一种将数据发送到服务器的方法。

4

0 回答 0