代码拉取完成,页面将自动刷新
# HttpClient
**Description:**
  Represents an HTTP client.
## post
**Type:** Function.
**Description:**
  Starts a non-blocking POST request with a JSON body.
**Signature:**
```tl
post: function(self: HttpClient, url: string, json: string, timeout: number, callback: function(data: string | nil)): integer
```
**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). |
| callback | function | Called when the request finishes. It receives the response text, or nil if the request fails or is cancelled. |
**Returns:**
| Return Type | Description |
| --- | --- |
| integer | The request handle, or 0 if the request cannot be scheduled. |
## post
**Type:** Function.
**Description:**
  Starts a non-blocking POST request with custom headers and a JSON body.
**Signature:**
```tl
post: function(self: HttpClient, url: string, headers: {string}, json: string, timeout: number, callback: function(data: string | nil)): integer
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| url | string | The URL to make the request to. |
| headers | \{string} | The headers to send in the request. Each header should be in the format "name: value". |
| json | string | The JSON text to send in the request. |
| timeout | number | [optional] The request timeout in seconds (default is 5 seconds). |
| callback | function | Called when the request finishes. It receives the response text, or nil if the request fails or is cancelled. |
**Returns:**
| Return Type | Description |
| --- | --- |
| integer | The request handle, or 0 if the request cannot be scheduled. |
## post
**Type:** Function.
**Description:**
  Starts a non-blocking POST request with custom headers and a JSON body, and optionally consumes the response stream in chunks before completion.
**Signature:**
```tl
post: function(self: HttpClient, url: string, headers: {string}, json: string, timeout: number, partCallback: function(data: string): boolean, callback: function(data: string | nil)): integer
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| url | string | The URL to make the request to. |
| headers | \{string} | The headers to send in the request. Each header should be in the format "name: value". |
| json | string | The JSON text to send in the request. |
| timeout | number | [optional] The request timeout in seconds (default is 5 seconds). |
| partCallback | function | [optional] Called when response chunks arrive. Return `true` to stop and cancel the request early. |
| callback | function | Called when the request finishes. It receives the full response text, or nil if the request fails or is cancelled. |
**Returns:**
| Return Type | Description |
| --- | --- |
| integer | The request handle, or 0 if the request cannot be scheduled. |
## postAsync
**Type:** Function.
**Description:**
  Sends a POST request with a JSON body and waits for the response text.
**Signature:**
```tl
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 text, or nil if the request fails. |
## postAsync
**Type:** Function.
**Description:**
  Sends a POST request with custom headers and a JSON body, and optionally consumes the response stream in chunks before completion.
**Signature:**
```tl
postAsync: function(self: HttpClient, url: string, headers: {string}, json: string, timeout?: number, partCallback?: function(data: string): boolean): string | nil
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| url | string | The URL to make the request to. |
| headers | \{string} | The headers to send in the request. Each header should be in the format "name: value". |
| json | string | The JSON text to send in the request. |
| timeout | number | [optional] The request timeout in seconds (default is 5 seconds). |
| partCallback | function | [optional] Called when response chunks arrive. Return `true` to stop and cancel the request early. |
**Returns:**
| Return Type | Description |
| --- | --- |
| string | The response text, or nil if the request fails. |
## get
**Type:** Function.
**Description:**
  Starts a non-blocking GET request.
**Signature:**
```tl
get: function(self: HttpClient, url: string, timeout: number, callback: function(data: string | nil)): integer
```
**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). |
| callback | function | Called when the request finishes. It receives the response text, or nil if the request fails or is cancelled. |
**Returns:**
| Return Type | Description |
| --- | --- |
| integer | The request handle, or 0 if the request cannot be scheduled. |
## getAsync
**Type:** Function.
**Description:**
  Sends a GET request and waits for the response text.
**Signature:**
```tl
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 text, or nil if the request fails. |
## download
**Type:** Function.
**Description:**
  Starts a non-blocking file download.
**Signature:**
```tl
download: function(self: HttpClient, url: string, fullPath: string, timeout?: number, progress?: function(interrupted: boolean, current: integer, total: integer): boolean): integer
```
**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 | function | [optional] Reports download progress with interrupted, current, and total. Return `true` to cancel the download. |
**Returns:**
| Return Type | Description |
| --- | --- |
| integer | The request handle, or 0 if the request cannot be scheduled. |
## downloadAsync
**Type:** Function.
**Description:**
  Downloads a file and waits until it finishes. This method must be called from a coroutine/thread.
**Signature:**
```tl
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 | function | [optional] Reports download progress with current and total byte counts. Return `true` to cancel the download. |
**Returns:**
| Return Type | Description |
| --- | --- |
| boolean | `true` if the download finishes successfully; otherwise `false`. |
## cancel
**Type:** Function.
**Description:**
  Requests cancellation for an in-flight request.
**Signature:**
```tl
cancel: function(self: HttpClient, requestId: integer): boolean
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| requestId | integer | The request handle returned by post, get, or download. |
**Returns:**
| Return Type | Description |
| --- | --- |
| boolean | `true` if the request was found and cancellation was requested. |
## isRequestActive
**Type:** Function.
**Description:**
  Checks whether a request is still active.
**Signature:**
```tl
isRequestActive: function(self: HttpClient, requestId: integer): boolean
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| requestId | integer | The request handle returned by post, get, or download. |
**Returns:**
| Return Type | Description |
| --- | --- |
| boolean | `true` if the request is still running. |
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。