title: Delphi Indy IdHTTP Authorization
body: <p>I'm trying to get user photos in Exchange using <code>IdHTTP</code> through <code>REST API</code></p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/office/jj190905(v=exchg.150).aspx" rel="nofollow">How to: Get user photos by using EWS in Exchange</a></p>
  
  <pre><code>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+'&amp;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;
  </code></pre>
  
  <p>I get <code>HTTP/1.1 401 Anonymous Request Disallowed</code>.</p>
  
  <p>Why the <code>idHTTP</code> not send the Authentication with request ? What i'm doing wrong ?</p>