Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

Http Client Demo

 Post Reply Post Reply
Author
Ekerhovd Ole View Drop Down
New Member
New Member
Avatar

Joined: 06 Nov 2010
Posts: 19
Post Options Post Options   Quote Ekerhovd Ole Quote  Post ReplyReply Direct Link To This Post Topic: Http Client Demo
    Posted: 03 Nov 2019 at 9:16am
I try to make a request to a Rest service using the Http Client Demo as a template.

The service requires a Basic Authentication, how can I do that?

Regards,
Ole
Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2552
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 05 Nov 2019 at 3:27pm
Hello Ole, you can use this code:

 MyHttpClient.OnSendingRequest := procedure(Req: THttpRequest)
    begin
      C.Request.Headers.SetValue('authorization', TSparkleUtils.BasicAuthHeaderValue('user', ‘password'));
    end;
Back to Top
Ekerhovd Ole View Drop Down
New Member
New Member
Avatar

Joined: 06 Nov 2010
Posts: 19
Post Options Post Options   Quote Ekerhovd Ole Quote  Post ReplyReply Direct Link To This Post Posted: 09 Nov 2019 at 8:28am
Hello Wagner

How can I implement that in this code?

procedure TForm2.Button1Click(Sender: TObject);
var
  Client : THttpClient;
  Request : THttpRequest;
  Response : THttpResponse;
begin
  request:=nil;
  response:=nil;
  client:=tHttpClient.Create;
  try
    request:=client.CreateRequest;
    request.uri:='https://xxxxxxxx';
    request.Method:='GET';
    response:=client.Send(request);
    request.SetContent(tencoding.UTF8.GetBytes('text/html'));
    if response.StatusCode=200 then
    showmessage('OK');
  finally
    request.Free;
    response.Free;
    client.Free;
  end;
end;
Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2552
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 10 Nov 2019 at 11:57pm
Hi Ole, use this:

procedure TForm2.Button1Click(Sender: TObject);
var
  Client : THttpClient;
  Request : THttpRequest;
  Response : THttpResponse;
begin
  request:=nil;
  response:=nil;
  client:=tHttpClient.Create;
  try
    client.OnSendingRequest := procedure(Req: THttpRequest)
    begin
      Req.Headers.SetValue('authorization', TSparkleUtils.BasicAuthHeaderValue('user', ‘password'));
    end;

    request:=client.CreateRequest;
    request.uri:='https://xxxxxxxx';
    request.Method:='GET';
    response:=client.Send(request);
    request.SetContent(tencoding.UTF8.GetBytes('text/html'));
    if response.StatusCode=200 then
    showmessage('OK');
  finally
    request.Free;
    response.Free;
    client.Free;
  end;
end;
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down