Delphi Indy IdHTTP Authorization

你说的曾经没有我的故事 提交于 2019-12-11 12:43:29

问题


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 ?

来源:https://stackoverflow.com/questions/37316786/delphi-indy-idhttp-authorization

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!