我试图将文件上传到 webdav 服务器,但我得到 (401) 未经授权。我不知道我的问题是与服务器权限有关还是与我的代码有关?这是我用来测试的代码:

string sourceFilePath = @"C:\testfile.txt";
string webAddress = "http://ip:port/";
string destinationFilePath = webAddress + "testfile.txt";

WebClient webClient = new WebClient();
webClient.UseDefaultCredentials = true;
webClient.UploadFile(destinationFilePath, "PUT", sourceFilePath);
webClient.Dispose();
但是,使用以下代码我可以从 webdav 服务器下载文件:
string webAddress = "http://ip:port/";
string sourceFilePath = webAddress + "testfile.txt";
string destinationFilePath = @"C:\testfile.txt";

WebClient webClient = new WebClient();
webClient.UseDefaultCredentials = true;
webClient.DownloadFile(sourceFilePath, destinationFilePath);
webClient.Dispose();
服务器正在运行 iis 8,并配置了 webdav 创作规则。
我已经在服务器上的目标文件夹上为我的用户设置了完全控制权。
编辑:意识到即使我删除了创作规则,我也可以下载文件,这是为什么?
创作规则如下所示:
c# - webdav WebClient.Upload (401) 未经授权-LMLPHP

最佳答案

安装并启用 Windows 身份验证解决了这个问题。
现在我认为它需要启用似乎是逻辑......

关于c# - webdav WebClient.Upload (401) 未经授权,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21882994/

10-12 14:24