我正在尝试通过Exchange Serve Web服务获取AD用户图片。但是,当我将代码运行到服务器时,它返回以下错误:
远程服务器返回错误:(401)未经授权。
我邮箱的凭证是正确的!
HttpWebRequest request =
WebRequest.Create("https://www.contoso.com/ews/exchange.asmx/s/GetUserPhoto?email=sadie@contoso.com&size=HR240x240";)
as HttpWebRequest;
CredentialCache cc = new CredentialCache();
cc.Add(
new Uri("https://www.contoso.com/ews/exchange.asmx/s/GetUserPhoto?email=sadie@contoso.com&size=HR240x240";),
"NTLM",
new NetworkCredential("domainusername", "Mypass"));
request.Credentials = cc;
request.Credentials =cc;
// Submit the request.
using (HttpWebResponse resp = request.GetResponse() as HttpWebResponse)
{
// Take the response and save it as an image.
Bitmap image = new Bitmap(resp.GetResponseStream());
image.Save("Sadie.jpg");
}
答案 0 :(得分:0)
如果你尝试怎么办?
new NetworkCredential("username", "password", "domain")
确保URI是正确的(不是www.contoso.com )。