-
Notifications
You must be signed in to change notification settings - Fork 2
/
sfrmMain.pas
76 lines (65 loc) · 1.86 KB
/
sfrmMain.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
unit sfrmMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls, REST.Types, Vcl.ExtCtrls, REST.Client, Data.Bind.Components,
Data.Bind.ObjectScope, json, Data.Cloud.CloudAPI, Data.Cloud.AzureAPI;
type
TfrmMain = class(TForm)
btnStart: TButton;
memResponse: TMemo;
RESTClient: TRESTClient;
RESTRequest: TRESTRequest;
RESTResponse: TRESTResponse;
edAPIURL: TLabeledEdit;
Panel1: TPanel;
edSubKey: TLabeledEdit;
edImgURL: TLabeledEdit;
procedure btnStartClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure TfrmMain.btnStartClick(Sender: TObject);
var
lparam : Trestrequestparameter;
imgProcessed: bool;
jsonObj, jsonStatus: TJSONObject;
begin
memResponse.Lines.Clear;
RESTClient.BaseURL := edAPIURL.Text;
RESTRequest.Method:=rmpost;
imgProcessed := false;
try
RESTRequest.Params.Clear;
RESTResponse.RootElement := '';
lparam := RESTRequest.Params.AddItem;
lparam.name := 'Ocp-Apim-Subscription-Key';
lparam.Value := edSubKey.Text;
lparam.ContentType := ctNone;
lparam.Kind := pkHTTPHEADER;
//This one is Important otherwise the '==' will get url encoded
lparam.Options := [poDoNotEncode];
lparam := RESTRequest.Params.AddItem;
lparam.name := 'data';
lparam.Value := '{"url":"' + edImgURL.Text + '"}';
lparam.ContentType := ctAPPLICATION_JSON;
lparam.Kind := pkGETorPOST;
RESTRequest.Execute;
if not RESTResponse.Status.Success then
showmessage(RESTResponse.StatusText + ' ' +
inttostr(RESTResponse.StatusCode))
else
begin
memResponse.Lines.Add(RESTResponse.JSONText);
end;
finally
end;
end;
end.