我需要从SharePoint Online网站下载用户的个人资料图像,然后将该图像插入PPT。为此,我使用下面的C#代码:
string userPhotoURL = "https://microsoft.sharepoint.com/_layouts/15/userphoto.aspx?size=M&username=username@microsoft.com";
using (var client = new WebClient())
{
client.Headers.Add("User-Agent: Other");
client.Credentials = Utility.GetSharePointOnlineCredentials(); // includes username and SecureString password
client.DownloadFile(userPhotoURL, "D:\sample.jpg");
}
// More code to read the D:\sample.jpg and insert it into PPT
但是,上面是403回复。
注意:我需要从服务器端实现此目的。
答案 0 :(得分:1)
我自己解决了这个问题。基本上我在发送请求时添加了一个额外的标题,如下所示:
client.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");