Skip to main content

HttpClient

Description:

  Represents an HTTP client.

postAsync

Type: Function.

Description:

  Makes a POST request to the specified URL with the specified JSON text and returns the response in text.

Signature:

postAsync: function(self: HttpClient, url: string, json: string, timeout?: number): string | nil

Parameters:

ParameterTypeDescription
urlstringThe URL to make the request to.
jsonstringThe JSON text to send in the request.
timeoutnumber[optional] The request timeout in seconds (default is 5 seconds).

Returns:

Return TypeDescription
stringThe response in text,or nil if the request fails.

getAsync

Type: Function.

Description:

  Makes a GET request to the specified URL and returns the response in text.

Signature:

getAsync: function(self: HttpClient, url: string, timeout?: number): string | nil

Parameters:

ParameterTypeDescription
urlstringThe URL to make the request to.
timeoutnumber[optional] The request timeout in seconds (default is 5 seconds).

Returns:

Return TypeDescription
stringThe response in text,or nil if the request fails.

downloadAsync

Type: Function.

Description:

  Downloads a file asynchronously from the specified URL and saves it to the specified path. Should be run in a coroutine.

Signature:

downloadAsync: function(self: HttpClient, url: string, fullPath: string, timeout?: number, progress?: function(current: integer, total: integer): boolean): boolean

Parameters:

ParameterTypeDescription
urlstringThe URL of the file to download.
fullPathstringThe full path where the downloaded file should be saved.
timeoutnumber[optional] The download timeout in seconds (default is 30 seconds).
progressstring[optional] A callback function that is called periodically to report the download progress. The function receives two parameters: current (the number of bytes downloaded so far) and total (the total number of bytes to be downloaded).If the function returns true, the download will be canceled.

Returns:

Return TypeDescription
booleanA boolean value indicating whether the download was done successfully.