frmmain.pas 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. unit frmmain;
  2. interface
  3. uses
  4. Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  5. Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, IPPeerClient, REST.Client,
  6. REST.Authenticator.Basic, Data.Bind.Components, Data.Bind.ObjectScope,
  7. Vcl.StdCtrls, Vcl.Grids, Vcl.DBGrids, Vcl.ExtCtrls, Vcl.DBCtrls,
  8. Datasnap.DBClient, System.Net.URLClient, System.Net.HttpClient,
  9. System.Net.HttpClientComponent, IdBaseComponent, IdComponent, IdTCPConnection,
  10. IdTCPClient, IdHTTP;
  11. type
  12. TForm1 = class(TForm)
  13. DSRest: TDataSource;
  14. CDSRest: TClientDataSet;
  15. DBNavigator1: TDBNavigator;
  16. DBGrid1: TDBGrid;
  17. EURL: TEdit;
  18. BFetch: TButton;
  19. Label1: TLabel;
  20. Label2: TLabel;
  21. EUserName: TEdit;
  22. LEPassword: TLabel;
  23. EPassword: TEdit;
  24. RestClient: TIdHTTP;
  25. procedure BFetchClick(Sender: TObject);
  26. private
  27. { Private declarations }
  28. public
  29. { Public declarations }
  30. end;
  31. var
  32. Form1: TForm1;
  33. implementation
  34. {$R *.dfm}
  35. procedure TForm1.BFetchClick(Sender: TObject);
  36. Var
  37. URL : String;
  38. Response : TMemoryStream;
  39. begin
  40. URL:=EURL.Text;
  41. if Pos('?',URL)=0 then
  42. URL:=URL+'?'
  43. else
  44. URL:=URL+'&';
  45. URL:=URL+'fmt=cds';
  46. Response:=TMemoryStream.Create;
  47. With RestClient.Request do
  48. begin
  49. UserName:=EUserName.Text;
  50. Password:=EPassword.Text;
  51. end;
  52. RestClient.Get(URL,Response);
  53. Response.Position:=0;
  54. CDSRest.LoadFromStream(Response);
  55. end;
  56. end.