|
@@ -14,6 +14,9 @@ uses
|
|
|
cxButtons, BCEditor.Editor.Base, BCEditor.Editor, dxSkinscxPCPainter,
|
|
|
dxBarBuiltInMenu, cxPC, System.ImageList, Vcl.ImgList, cxCheckBox;
|
|
|
|
|
|
+type
|
|
|
+ TMethodType = (mtGET, mtPOST, mtPATCH, mtPUT, mtDELETE);
|
|
|
+
|
|
|
type
|
|
|
TfrmMain = class(TForm)
|
|
|
OpenDialog: TOpenDialog;
|
|
@@ -157,6 +160,9 @@ type
|
|
|
procedure DeletePreset(const AID: Integer);
|
|
|
procedure LoadPreset;
|
|
|
procedure SavePreset;
|
|
|
+ procedure ShowError(const AErrorText: string);
|
|
|
+ procedure DoGETRequest(const AMethodType: TMethodType);
|
|
|
+ procedure DoPOSTRequest(const AMethodType: TMethodType);
|
|
|
public
|
|
|
{ Public-Deklarationen }
|
|
|
end;
|
|
@@ -329,7 +335,13 @@ end;
|
|
|
|
|
|
procedure TfrmMain.comboMethodPropertiesChange(Sender: TObject);
|
|
|
begin
|
|
|
- tabPostData.TabVisible := comboMethod.ItemIndex = 1;
|
|
|
+ tabPostData.TabVisible := (comboMethod.ItemIndex = 1) or (comboMethod.ItemIndex = 2) or (comboMethod.ItemIndex = 3);
|
|
|
+
|
|
|
+ case comboMethod.ItemIndex of
|
|
|
+ 1: tabPostData.Caption := 'Post Data';
|
|
|
+ 2: tabPostData.Caption := 'Patch Data';
|
|
|
+ 3: tabPostData.Caption := 'Put Data';
|
|
|
+ end;
|
|
|
|
|
|
if (comboMethod.ItemIndex = 0) and (PageControlParams.ActivePage = nil) then
|
|
|
begin
|
|
@@ -366,7 +378,7 @@ begin
|
|
|
except
|
|
|
on E: Exception do
|
|
|
begin
|
|
|
- MessageDlg(E.Message, mtError, [mbOK], 0);
|
|
|
+ ShowError(E.Message);
|
|
|
end;
|
|
|
end;
|
|
|
FActiveEditor.Lines.Clear;
|
|
@@ -385,7 +397,7 @@ begin
|
|
|
except
|
|
|
on E: Exception do
|
|
|
begin
|
|
|
- MessageDlg(E.Message, mtError, [mbOK], 0);
|
|
|
+ ShowError(E.Message);
|
|
|
end;
|
|
|
end;
|
|
|
FActiveEditor.Lines.Clear;
|
|
@@ -416,6 +428,64 @@ begin
|
|
|
comboPresets.ItemIndex := comboPresets.Properties.Items.Count - 1;
|
|
|
end;
|
|
|
|
|
|
+procedure TfrmMain.DoGETRequest(const AMethodType: TMethodType);
|
|
|
+var
|
|
|
+ dmy: string;
|
|
|
+begin
|
|
|
+ try
|
|
|
+ case AMethodType of
|
|
|
+ mtGET: dmy := HTTP.Get(edtFullURL.Text);
|
|
|
+ mtDELETE: dmy := HTTP.Delete(edtFullURL.Text);
|
|
|
+ end;
|
|
|
+
|
|
|
+ if HTTP.ResponseCode <> 200 then
|
|
|
+ begin
|
|
|
+ ShowError(HTTP.ResponseText);
|
|
|
+ end;
|
|
|
+ except
|
|
|
+ on E: Exception do
|
|
|
+ begin
|
|
|
+ ShowError(E.Message);
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+
|
|
|
+ EditorContent.Lines.Text := dmy;
|
|
|
+ EditorResponseHeaders.Lines.Text := HTTP.Response.RawHeaders.Text;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TfrmMain.DoPOSTRequest(const AMethodType: TMethodType);
|
|
|
+var
|
|
|
+ dmy: string;
|
|
|
+ strstream: TStringStream;
|
|
|
+begin
|
|
|
+ strstream := TStringStream.Create(EditorPostData.Lines.Text, TEncoding.UTF8);
|
|
|
+ try
|
|
|
+ HTTP.Request.ContentType := comboPostContentType.Text;
|
|
|
+ try
|
|
|
+ case AMethodType of
|
|
|
+ mtPOST: dmy := HTTP.Post(edtFullURL.Text, strstream);
|
|
|
+ mtPATCH: dmy := HTTP.Patch(edtFullURL.Text, strstream);
|
|
|
+ mtPUT: dmy := HTTP.Put(edtFullURL.Text, strstream);
|
|
|
+ end;
|
|
|
+
|
|
|
+ if HTTP.ResponseCode <> 200 then
|
|
|
+ begin
|
|
|
+ ShowError(HTTP.ResponseText);
|
|
|
+ end;
|
|
|
+ except
|
|
|
+ on E: Exception do
|
|
|
+ begin
|
|
|
+ ShowError(E.Message);
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+ finally
|
|
|
+ strstream.Free;
|
|
|
+ end;
|
|
|
+
|
|
|
+ EditorContent.Lines.Text := dmy;
|
|
|
+ EditorResponseHeaders.Lines.Text := HTTP.Response.RawHeaders.Text;
|
|
|
+end;
|
|
|
+
|
|
|
procedure TfrmMain.dxBarButton6Click(Sender: TObject);
|
|
|
begin
|
|
|
Close;
|
|
@@ -597,7 +667,7 @@ end;
|
|
|
|
|
|
procedure TfrmMain.FormResize(Sender: TObject);
|
|
|
begin
|
|
|
- Image.Left := Width - 70;
|
|
|
+ Image.Left := Width - 45;
|
|
|
end;
|
|
|
|
|
|
procedure TfrmMain.FormShow(Sender: TObject);
|
|
@@ -783,7 +853,7 @@ begin
|
|
|
except
|
|
|
on E: Exception do
|
|
|
begin
|
|
|
- MessageDlg(E.Message, mtError, [mbOK], 0);
|
|
|
+ ShowError(E.Message);
|
|
|
end;
|
|
|
end;
|
|
|
FActiveEditor.Lines.Clear;
|
|
@@ -802,7 +872,7 @@ begin
|
|
|
except
|
|
|
on E: Exception do
|
|
|
begin
|
|
|
- MessageDlg(E.Message, mtError, [mbOK], 0);
|
|
|
+ ShowError(E.Message);
|
|
|
end;
|
|
|
end;
|
|
|
FActiveEditor.Lines.Clear;
|
|
@@ -817,9 +887,7 @@ end;
|
|
|
|
|
|
procedure TfrmMain.Run;
|
|
|
var
|
|
|
- dmy: string;
|
|
|
tick: Cardinal;
|
|
|
- strstream: TStringStream;
|
|
|
begin
|
|
|
EditorContent.Lines.Clear;
|
|
|
EditorResponseHeaders.Lines.Clear;
|
|
@@ -846,45 +914,32 @@ begin
|
|
|
if comboMethod.ItemIndex = 0 then
|
|
|
begin
|
|
|
// GET
|
|
|
- try
|
|
|
- dmy := HTTP.Get(edtFullURL.Text);
|
|
|
- if HTTP.ResponseCode <> 200 then
|
|
|
- begin
|
|
|
- MessageDlg(HTTP.ResponseText, mtError, [mbOK], 0);
|
|
|
- end;
|
|
|
- except
|
|
|
- on E: Exception do
|
|
|
- begin
|
|
|
- MessageDlg(E.Message, mtError, [mbOK], 0);
|
|
|
- end;
|
|
|
- end;
|
|
|
+ DoGETRequest(mtGET);
|
|
|
end
|
|
|
else
|
|
|
if comboMethod.ItemIndex = 1 then
|
|
|
begin
|
|
|
// POST
|
|
|
- strstream := TStringStream.Create(EditorPostData.Lines.Text, TEncoding.UTF8);
|
|
|
- try
|
|
|
- HTTP.Request.ContentType := comboPostContentType.Text;
|
|
|
- try
|
|
|
- dmy := HTTP.Post(edtFullURL.Text, strstream);
|
|
|
- if HTTP.ResponseCode <> 200 then
|
|
|
- begin
|
|
|
- MessageDlg(HTTP.ResponseText, mtError, [mbOK], 0);
|
|
|
- end;
|
|
|
- except
|
|
|
- on E: Exception do
|
|
|
- begin
|
|
|
- MessageDlg(E.Message, mtError, [mbOK], 0);
|
|
|
- end;
|
|
|
- end;
|
|
|
- finally
|
|
|
- strstream.Free;
|
|
|
- end;
|
|
|
+ DoPOSTRequest(mtPOST);
|
|
|
+ end
|
|
|
+ else
|
|
|
+ if comboMethod.ItemIndex = 2 then
|
|
|
+ begin
|
|
|
+ // PATCH
|
|
|
+ DoPOSTRequest(mtPATCH);
|
|
|
+ end
|
|
|
+ else
|
|
|
+ if comboMethod.ItemIndex = 3 then
|
|
|
+ begin
|
|
|
+ // PUT
|
|
|
+ DoPOSTRequest(mtPUT);
|
|
|
+ end
|
|
|
+ else
|
|
|
+ if comboMethod.ItemIndex = 4 then
|
|
|
+ begin
|
|
|
+ // DELETE
|
|
|
+ DoGETRequest(mtDELETE);
|
|
|
end;
|
|
|
-
|
|
|
- EditorContent.Lines.Text := dmy;
|
|
|
- EditorResponseHeaders.Lines.Text := HTTP.Response.RawHeaders.Text;
|
|
|
finally
|
|
|
dxStatusBar.Panels[1].Text := FormatFloat('Response Time: 0, ms', GetTickCount - tick);
|
|
|
Screen.Cursor := crDefault;
|
|
@@ -946,4 +1001,9 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
+procedure TfrmMain.ShowError(const AErrorText: string);
|
|
|
+begin
|
|
|
+ MessageDlg(AErrorText, mtError, [mbOK], 0);
|
|
|
+end;
|
|
|
+
|
|
|
end.
|