Web¶
Internet HTTP request/post methods.
There is a pre-defined variable
HTTPClient
to use.
EHTTPStatus.AsInteger¶
property EHTTPStatus.AsInteger: Integer;
EHTTPStatus.AsString¶
property EHTTPStatus.AsString: String;
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.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.
TInternetSocket.Create¶
function TInternetSocket.Create(AHost: String; APort: UInt16; UseSSL: Boolean): TInternetSocket; static;
Basic internet socket functionality.
The socket is blocking which means Read
calls will wait for data to arrive.
Use either ReadWriteTimeout() / HasData() / ReadStringUntil() to avoid hanging.
TInternetSocket.Connect¶
procedure TInternetSocket.Connect;
Connects to the host and port.
TInternetSocket.Close¶
procedure TInternetSocket.Close;
Closes the socket
TInternetSocket.HasData¶
function TInternetSocket.HasData: Boolean;
Returns true if there is data waiting to be read.
TInternetSocket.Read¶
function TInternetSocket.Read(MaxLen: Integer = 8192): TByteArray;
Read bytes from the socket up to MaxLen
bytes.
Note
By default this call is blocking - it will wait until there is data to be read.
To change this behavior use ReadWriteTimeout
or use HasData
.
TInternetSocket.ReadUntil¶
function TInternetSocket.ReadUntil(Seq: TByteArray; Timeout: Integer): TByteArray;
Reads 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.
TInternetSocket.ReadString¶
function TInternetSocket.ReadString(MaxLen: Integer = 8192): String;
ReadString a string from the socket up to MaxLen
bytes.
TInternetSocket.ReadStringUntil¶
function TInternetSocket.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 ReadStringing data which is terminated with consistent endings.
TInternetSocket.Write¶
function TInternetSocket.Write(Data: TByteArray): Integer;
Write bytes to the socket.
TInternetSocket.WriteString¶
function TInternetSocket.WriteString(Str: String): Integer;
Write a string to the socket.
TInternetSocket.LocalAddress¶
property TInternetSocket.LocalAddress: String;
TInternetSocket.RemoteAddress¶
property TInternetSocket.RemoteAddress: String;
TInternetSocket.ReadWriteTimeout¶
property TInternetSocket.ReadWriteTimeout: Integer
property TInternetSocket.ReadWriteTimeout(Value: Integer)
Timeout (in milliseconds) on Read/Write operations.
TInternetSocket.ConnectTimeout¶
property TInternetSocket.ConnectTimeout: Integer;
property TInternetSocket.ConnectTimeout(Value: Integer);
Connect timeout (in milliseconds).
TInternetSocket.LastError¶
property TInternetSocket.LastError: Integer;
Returns the sockets last error code.
TInternetSocketASync.Create¶
function TInternetSocketASync.Create(AHost: String; APort: UInt16; UseSSL: Boolean): TInternetSocketASync; static;
Internet socket but runs in the background and calls the OnData callback when data arrives.
TInternetSocketASync.OnData¶
property TInternetSocketASync.OnData: TSocketDataEvent;
property TInternetSocketASync.OnData(Value: TSocketDataEvent);
TInternetSocketASync.OnDisconnect¶
property TInternetSocketASync.OnDisconnect: TSocketDisconnectEvent;
property TInternetSocketASync.OnDisconnect(Value: TSocketDisconnectEvent);
TInternetSocketASync.Running¶
property TInternetSocketASync.Running: Boolean;
TInternetSocketServer.Create¶
function TInternetSocketServer.Create(APort: Integer): TInternetSocketServer;
function TInternetSocketServer.Create(AHost: String; APort: Integer): TInternetSocketServer;
TInternetSocketServer.Start¶
procedure TInternetSocketServer.Start;
TInternetSocketServer.Stop¶
procedure TInternetSocketServer.Stop;
TInternetSocketServer.Running¶
function TInternetSocketServer.Running: Boolean;
TInternetSocketServer.ConnectionCount¶
property TInternetSocketServer.ConnectionCount: Integer;
TInternetSocketServer.OnHandleClient¶
property TInternetSocketServer.OnHandleClient: THandleClientEvent;
property TInternetSocketServer.OnHandleClient(Value: THandleClientEvent);
TInternetSocketServer.OnAllowClient¶
property TInternetSocketServer.OnAllowClient: TAllowClientEvent;
property TInternetSocketServer.OnAllowClient(Value: TAllowClientEvent);
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.