以编程方式从基于声明身份验证的 SharePoint 2010 网站下载文件
我有一个控制台应用程序用于从 SharePoint 站点下载文件。 Sharepoint 站点使用基于声明的身份验证。
此代码引发 403 Forbidden 异常。指定的网络凭据具有对该站点的完全访问权限,并且能够从浏览器下载相同的文件。
WebClient webClient = new WebClient();
webClient.Credentials = new NetworkCredential(username,Password,domain);
byte[] fileData = webClient.DownloadData(urlOfAFile);
FileStream file = File.Create(localPath);
file.Write(fileData, 0, fileData.Length);
知道如何解决这个问题吗?
I have a console application to download a file from a SharePoint site. The sharepoint site uses claims based authentication.
This code throws a 403 Forbidden exception. The specified Network credential has full access to the site, and is able to download the same file from a browser.
WebClient webClient = new WebClient();
webClient.Credentials = new NetworkCredential(username,Password,domain);
byte[] fileData = webClient.DownloadData(urlOfAFile);
FileStream file = File.Create(localPath);
file.Write(fileData, 0, fileData.Length);
Any idea how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许有点晚了,但是在发出请求之前添加正确的请求标头可以解决问题:
Maybe a bit late, but adding the right request header before making the request solves the problem:
我也遇到了这个问题,下面是我的研究:
这是文章: https://msdn.microsoft.com/en-us/library/office/hh124553(v=office.14).aspx
I also encounter this issue, and below is my research:
here is the article: https://msdn.microsoft.com/en-us/library/office/hh124553(v=office.14).aspx