Delphi ActiveX
Delphi ActiveX
POST application/json HTTPS Request
See more HTTP Examples
Demonstrates how to send an HTTPS POST where the request body and response body both have the application/json Content-Type. Also demonstrates how to add a few custom headers to the request.Chilkat Delphi ActiveX Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Integer;
http: TChilkatHttp;
url: WideString;
jsonRequestBody: WideString;
resp: TChilkatHttpResponse;
jsonResponseStr: WideString;
begin
success := 0;
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code
http := TChilkatHttp.Create(Self);
// Add a few custom headers.
http.SetRequestHeader('Client-ID','my_client_id');
http.SetRequestHeader('Client-Token','my_client_token');
http.Accept := 'application/json';
url := 'https://api.fiscallog.eu/sign/v1';
jsonRequestBody := '{ .... }';
resp := TChilkatHttpResponse.Create(Self);
success := http.HttpStr('POST',url,jsonRequestBody,'utf-8','application/json',resp.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(http.LastErrorText);
Exit;
end;
Memo1.Lines.Add('Response status code = ' + IntToStr(resp.StatusCode));
jsonResponseStr := resp.BodyStr;
Memo1.Lines.Add(jsonResponseStr);
end;