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:
Parameter | Type | Description |
---|---|---|
url | string | The URL to make the request to. |
json | string | The JSON text to send in the request. |
timeout | number | [optional] The request timeout in seconds (default is 5 seconds). |
Returns:
Return Type | Description |
---|---|
string | The 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:
Parameter | Type | Description |
---|---|---|
url | string | The URL to make the request to. |
timeout | number | [optional] The request timeout in seconds (default is 5 seconds). |
Returns:
Return Type | Description |
---|---|
string | The 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:
Parameter | Type | Description |
---|---|---|
url | string | The URL of the file to download. |
fullPath | string | The full path where the downloaded file should be saved. |
timeout | number | [optional] The download timeout in seconds (default is 30 seconds). |
progress | string | [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 Type | Description |
---|---|
boolean | A boolean value indicating whether the download was done successfully. |