我正在尝试使用WebcClient.DownloadFile()
下载Office 365 SharePoint库中存在的项目,但出现此异常:
例外情况:
The remote server returned an error: (403) Forbidden.
样例代码:
NetworkCredential credential = new NetworkCredential("username", "password", "aaa.onmicrosoft.com");
WebClient webClient = new WebClient();
webClient.Credentials = credential;
webClient.DownloadFile(@"https://aaa.sharepoint.com/testDoc/test.pdf", @"c:/test.pdf");
最佳答案
在朋友的帮助下,我设法破解了此SharePoint在线身份验证内容:)
WictorWilén向我指示this blog post的方向。
我的使用Wictors的WebClient调用声明了库代码...
var claimsHelper = new MsOnlineClaimsHelper(sharepointOnlineUrl, username, password);
var client = new WebClient();
client.Headers[ "Accept" ] = "/";
client.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
client.Headers.Add(HttpRequestHeader.Cookie, claimsHelper.CookieContainer.GetCookieHeader(new Uri(sharepointOnlineUrl)) );
var document = client.DownloadString( documentUrl );
关于c# - 无法下载Office 365 SharePoint库项目,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12671194/