我尝试使用IdHTTP
到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;
我得到HTTP/1.1 401 Anonymous Request Disallowed
。
为什么idHTTP
未向请求发送身份验证?我做错了什么?