Delphi ActiveX
Delphi ActiveX
Send a REST Request using StringBuilder Bodies
See more REST Examples
Demonstrates Rest.FullRequestSb, which sends a complete request whose text body is read from a StringBuilder and stores the text response body in a second StringBuilder.
Background. Using StringBuilder objects for the request and response bodies avoids extra string conversions, which is helpful when working with large payloads.
Chilkat Delphi ActiveX Downloads
var
success: Integer;
rest: TChilkatRest;
bTls: Integer;
bAutoReconnect: Integer;
sbRequest: TChilkatStringBuilder;
sbResponse: TChilkatStringBuilder;
responseText: WideString;
begin
success := 0;
rest := TChilkatRest.Create(Self);
bTls := 1;
bAutoReconnect := 1;
success := rest.Connect('example.com',443,bTls,bAutoReconnect);
if (success = 0) then
begin
Memo1.Lines.Add(rest.LastErrorText);
Exit;
end;
// FullRequestSb sends a request whose text body is read from a StringBuilder and stores the text
// response body in a second StringBuilder. This avoids extra string conversions for large bodies.
sbRequest := TChilkatStringBuilder.Create(Self);
sbRequest.Append('{ "query": "chilkat" }');
rest.AddHeader('Content-Type','application/json');
sbResponse := TChilkatStringBuilder.Create(Self);
success := rest.FullRequestSb('POST','/api/search',sbRequest.ControlInterface,sbResponse.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(rest.LastErrorText);
Exit;
end;
responseText := sbResponse.GetAsString();
if (sbResponse.LastMethodSuccess = 0) then
begin
Memo1.Lines.Add(sbResponse.LastErrorText);
Exit;
end;
Memo1.Lines.Add(responseText);