I'm trying to get user photos in Exchange using IdHTTP
through REST API
How to: Get user photos by using EWS in Exchange
procedure TsMain.IdHTTP1Authorization(Sender: TObject;
Authentication: TIdAuthentication; var Handled: Boolean);
begin
Authentication.Username := DomainName +'\'+ User;
Authentication.Username := User + #64 + DomainName;
Authentication.Password := Password;
Handled:=true;
end;
function TsMain.GetUserPhoto(const eMail: string):Boolean;
var
s: TStream;
ResponseCode: Integer;
begin
Result := False;
idHTTP:= TIdHttp.Create(Application);
s := TFileStream.Create('mypic.jpg', fmCreate);
try
idHTTP.OnAuthorization := IdHTTP1Authorization;
idHTTP.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(idHTTP);
idHTTP.HandleRedirects := True;
idHTTP.Request.BasicAuthentication:= true;
idHTTP.Get('https://ServerName/ews/Exchange.asmx/s/GetUserPhoto?email='+eMail+'&size=HR240x240', s);
ResponseCode := idHTTP.Response.ResponseCode;
case ResponseCode of
200:
begin
Result := True;
end;
else
ShowMessage(idHTTP.Response.ResponseText);
end;
finally
s.Free;
idHTTP.Free;
end;
end;
I get HTTP/1.1 401 Anonymous Request Disallowed
.
Why the idHTTP
not send the Authentication with request ? What i'm doing wrong ?