2016-05-19 12:07:38 +02:00
|
|
|
unit MainClientFormU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2019-03-19 12:06:13 +01:00
|
|
|
Winapi.Windows,
|
|
|
|
Winapi.Messages,
|
|
|
|
System.SysUtils,
|
|
|
|
System.Variants,
|
|
|
|
System.Classes,
|
|
|
|
Vcl.Graphics,
|
|
|
|
Vcl.Controls,
|
|
|
|
Vcl.Forms,
|
|
|
|
Vcl.Dialogs,
|
|
|
|
Vcl.StdCtrls;
|
2016-05-19 12:07:38 +02:00
|
|
|
|
|
|
|
type
|
|
|
|
TForm7 = class(TForm)
|
|
|
|
Button1: TButton;
|
|
|
|
Button2: TButton;
|
|
|
|
Memo1: TMemo;
|
|
|
|
procedure Button1Click(Sender: TObject);
|
|
|
|
procedure Button2Click(Sender: TObject);
|
|
|
|
private
|
|
|
|
FToken: String;
|
|
|
|
procedure SetToken(const Value: String);
|
|
|
|
{ Private declarations }
|
|
|
|
public
|
|
|
|
property Token: String read FToken write SetToken;
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
Form7: TForm7;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2020-09-24 21:30:45 +02:00
|
|
|
MVCFramework.RESTClient.Intf,
|
|
|
|
MVCFramework.RESTClient;
|
2016-05-19 12:07:38 +02:00
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
procedure TForm7.Button1Click(Sender: TObject);
|
2020-09-03 19:57:00 +02:00
|
|
|
|
2016-05-19 12:07:38 +02:00
|
|
|
var
|
2020-09-24 21:30:45 +02:00
|
|
|
lClt: IMVCRESTClient;
|
|
|
|
lResp: IMVCRESTResponse;
|
2016-05-19 12:07:38 +02:00
|
|
|
begin
|
2020-09-24 21:30:45 +02:00
|
|
|
lClt := TMVCRESTClient.New.BaseURL('localhost', 8080);
|
|
|
|
lResp := lClt.Post('/login');
|
|
|
|
Token := lResp.Content;
|
|
|
|
ShowMessage('In the next 15 seconds you can request protected resources. After your token will expires!');
|
2016-05-19 12:07:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm7.Button2Click(Sender: TObject);
|
|
|
|
var
|
2020-09-24 21:30:45 +02:00
|
|
|
lClt: IMVCRESTClient;
|
|
|
|
lResp: IMVCRESTResponse;
|
2016-05-19 12:07:38 +02:00
|
|
|
begin
|
2020-09-24 21:30:45 +02:00
|
|
|
lClt := TMVCRESTClient.New.BaseURL('localhost', 8080);
|
|
|
|
lClt.AddHeader('Authentication', 'bearer ' + FToken);
|
|
|
|
lResp := lClt.Get('/');
|
|
|
|
ShowMessage(lResp.StatusText + sLineBreak +
|
|
|
|
lResp.Content);
|
2016-05-19 12:07:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm7.SetToken(const Value: String);
|
|
|
|
begin
|
|
|
|
FToken := Value;
|
|
|
|
Memo1.Lines.Text := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|