Delphi ActiveX
Delphi ActiveX
HTTP POST with Binary Data in Request Body
See more HTTP Examples
Do an HTTPS POST with a binary request body.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;
fac: TCkFileAccess;
reqBody: Array of Byte;
resp: TChilkatHttpResponse;
responseStatusCode: Integer;
begin
success := 0;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := TChilkatHttp.Create(Self);
fac := TCkFileAccess.Create(Self);
reqBody := fac.ReadEntireFile('qa_data/pdf/helloWorld.pdf');
resp := TChilkatHttpResponse.Create(Self);
success := http.HttpBinary('POST','https://example.com/something',reqBody,'application/pdf',resp.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(http.LastErrorText);
Exit;
end;
responseStatusCode := resp.StatusCode;
Memo1.Lines.Add('Status code: ' + IntToStr(responseStatusCode));
// For example, if the response is XML, JSON, HTML, etc.
Memo1.Lines.Add('response body:');
Memo1.Lines.Add(resp.BodyStr);
end;