Web

Internet HTTP request/post methods.

  • There is a pre-defined variable HTTPClient to use.


TSimbaHTTPClient.Create

function TSimbaHTTPClient.Create: TSimbaHTTPClient; static;

Create a SimbaHTTPClient. This must be freed. Example:

var
  AnotherHTTPClient: TSimbaHTTPClient;
begin
  AnotherHTTPClient := TSimbaHTTPClient.Create();
  WriteLn AnotherHTTPClient.Get('www.google.com');
  AnotherHTTPClient.Free();
end;

TSimbaHTTPClient.CreateWithProxy

function TSimbaHTTPClient.CreateWithProxy(Host: String; User: String = ''; Pass: String = ''): THTTPClient; static;

Variant which uses a proxy for all connections.

TSimbaHTTPClient.OnDownloadProgress

property TSimbaHTTPClient.OnDownloadProgress: TSimbaHTTPDownloadingEvent;

TSimbaHTTPClient.OnExtractProgress

property TSimbaHTTPClient.OnExtractProgress: TSimbaHTTPExtractingEvent;

TSimbaHTTPClient.ConnectTimeout

property TSimbaHTTPClient.ConnectTimeout: Integer;

TSimbaHTTPClient.ReadWriteTimeout

property TSimbaHTTPClient.ReadWriteTimeout: Integer;

TSimbaHTTPClient.Cookies

property TSimbaHTTPClient.Cookies: TStringArray;

TSimbaHTTPClient.ResponseStatus

property TSimbaHTTPClient.ResponseStatus: EHTTPStatus;

Returns the response status of the last response.

  if (HTTPClient.ResponseStatus = EHTTPStaus.OK) then
    WriteLn('Response status was OK!')

TSimbaHTTPClient.ResponseHeaders

function TSimbaHTTPClient.ResponseHeaders: TStringArray;

TSimbaHTTPClient.ResponseHeader

property TSimbaHTTPClient.ResponseHeader[Name: String]: String;

TSimbaHTTPClient.RequestHeader

property TSimbaHTTPClient.RequestHeader[Name: String]: String;

TSimbaHTTPClient.Reset

procedure TSimbaHTTPClient.Reset;

TSimbaHTTPClient.Get

function TSimbaHTTPClient.Get(URL: String): String;

Return a webpages content as a string.

TSimbaHTTPClient.GetJson

function TSimbaHTTPClient.GetJson(URL: String): TSimbaJSONParser;

TSimbaHTTPClient.GetFile

procedure TSimbaHTTPClient.GetFile(URL, LocalFileName: String);

Save a webpages content to a local file.

TSimbaHTTPClient.GetZip

procedure TSimbaHTTPClient.GetZip(URL: String; OutputPath: String);

TSimbaHTTPClient.Head

function TSimbaHTTPClient.Head(URL: String): EHTTPStatus;

Header request. Headers will be written to HTTPClient.GetResponseHeaders()

TSimbaHTTPClient.Post

function TSimbaHTTPClient.Post(URL: String; Data: String): String;

HTTP post request.

  • Data is sent in request body.


TSimbaHTTPClient.Patch

function TSimbaHTTPClient.Patch(URL, Data: String): String;

TSimbaHTTPClient.Put

function TSimbaHTTPClient.Put(URL, Data: String): String;

TSimbaHTTPClient.Delete

function TSimbaHTTPClient.Delete(URL, Data: String): String;

TSimbaHTTPClient.Options

function TSimbaHTTPClient.Options(URL, Data: String): String;

TSimbaHTTPClient.PostForm

function TSimbaHTTPClient.PostForm(URL: String; Data: String): String;

Post form data (www-urlencoded)

TSimbaHTTPClient.PostFormFile

function TSimbaHTTPClient.PostFormFile(const URL, FieldName, FileName: string): String;

Post form with a local file file

URLOpenInBrowser

procedure URLOpenInBrowser(URL: String);

Opens a URL in the systems default internet browser.

URLFetch

function URLFetch(URL: String): String;

Simple method to return the contents of a webpage.

URLFetchToFile

function URLFetchToFile(URL, FileName: String): Boolean;

Simple method to download the contents of a webpage to a file.

URLEncode

function URLEncode(S: String): String;

URL encode a string. For example a space character is changed to %20.

URLDecode

function URLDecode(S: String): String;

Inverse of EncodeURLElement.

TSimbaInternetSocket.Create

function TSimbaInternetSocket.Create(AHost: String; APort: UInt16; UseSSL: Boolean): TSimbaInternetSocket; static;

Basic internet socket functionality. The socket is blocking which means Read calls will wait for data to arrive. Use either SetReadWriteTimeout() / HasData() / ReadStringUntil() to avoid hanging.

TSimbaInternetSocket.Connect

procedure TSimbaInternetSocket.Connect;

Connects to the host and port.

TSimbaInternetSocket.HasData

function TSimbaInternetSocket.HasData: Boolean;

Returns true if there is data waiting to be read.

TSimbaInternetSocket.ReadString

function TSimbaInternetSocket.ReadString(MaxLen: Integer = 8192): String;

Read a string from the socket up to MaxLen bytes.

TSimbaInternetSocket.ReadStringUntil

function TSimbaInternetSocket.ReadStringUntil(Seq: String; Timeout: Integer): String;

Reads a string until the data ends with Seq or Timeout (in milliseconds) is reached. This is useful if you are reading data which is terminated with consistent endings.

TSimbaInternetSocket.WriteString

function TSimbaInternetSocket.WriteString(Str: String): Integer;

Write a string to the socket.

TSimbaInternetSocket.GetReadWriteTimeout

function TSimbaInternetSocket.GetReadWriteTimeout: Integer

Returns the timeout (in milliseconds) on Read/Write operations.

TSimbaInternetSocket.SetReadWriteTimeout

function TSimbaInternetSocket.SetReadWriteTimeout(Value: Integer)

Sets the timeout (in milliseconds) on Read/Write operations.

TSimbaInternetSocket.GetConnectTimeout

function TSimbaInternetSocket.GetConnectTimeout: Integer;

Returns the connect timeout (in milliseconds).

TSimbaInternetSocket.SetConnectTimeout

function TSimbaInternetSocket.SetConnectTimeout(Value: Integer);

Sets the connect timeout (in milliseconds).

TSimbaInternetSocket.LastError

function TSimbaInternetSocket.LastError: Integer;

Returns the sockets last error code.

LoadSSL

function LoadSSL(Debug: Boolean = False): Boolean;

Loads SSL. This is automatically done on demand but is useful for debugging errors relating to loading openssl.