连接到 webDAV 时出现 404 Not Found

发布于 2024-08-30 01:49:37 字数 827 浏览 8 评论 0原文

我正在尝试连接到安全的 webDAV 文件夹并下载文件。我在尝试从服务器获取响应时遇到问题,因为当我调用 Request.GetResponse() 时,它总是给我一个 404 Not Found 错误。我可以通过映射驱动器使用 Windows 资源管理器连接到 webDAV 文件夹,但似乎无法在代码中执行此操作。我看过本网站上的其他帖子和其他在线帖子,但大多数似乎都集中在连接 Outlook 上。还有其他人遇到过这个问题吗?我使用的代码如下:


string URI = "https://transfer.mycompany.com/myDirectory/myFile.csv";
string username = "username";
string password = "password";
Request = (HttpWebRequest) WebRequest.Create(URI);
Request.Credentials = new NetworkCredential(username, password);
Request.Method = WebRequestMethods.Http.Get;
Request.Headers.Add("Translate", "f");
Response = (HttpWebResponse) Request.GetResponse();
contentLength = Convert.ToInt64(Response.GetResponseHeader("Content-Length"));

I am trying to connect to a secure webDAV folder and download a file. I am having problems just trying to get a response from the server and as it keeps giving me a 404 Not Found error as soon as I call Request.GetResponse(). I can connect to the webDAV folder using Windows Explorer by mapping a drive but cannot seem to do this in code. I have looked at other post on this site and others online but most seem to concentrate on connecting to Outlook. Has anybody else had this issue? The code I am using is as follows:


string URI = "https://transfer.mycompany.com/myDirectory/myFile.csv";
string username = "username";
string password = "password";
Request = (HttpWebRequest) WebRequest.Create(URI);
Request.Credentials = new NetworkCredential(username, password);
Request.Method = WebRequestMethods.Http.Get;
Request.Headers.Add("Translate", "f");
Response = (HttpWebResponse) Request.GetResponse();
contentLength = Convert.ToInt64(Response.GetResponseHeader("Content-Length"));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一抹苦笑 2024-09-06 01:49:37

当您从 Windows 资源管理器访问服务器时,使用 Fiddler 工具 查看还有哪些标头发送到服务器。尝试将这些标头添加到您的代码中,使其更类似于 WindowsExplorer 发送的请求,看看这是否有帮助。

Use the Fiddler tool to see what else headers are sent to the server, when you access it from Windows Explorer. Try adding these headers to your code to make it more similar to the request sent by WindowsExplorer and see if this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文