连接到 webDAV 时出现 404 Not Found
我正在尝试连接到安全的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您从 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.