Network Request
Provides HTTPS request and file download APIs for communicating with developer servers, enabling real-time data exchange and asset fetching.
TTMinis.game.request(opts)
Sends an HTTPS network request.
Parameters
Field | Type | Description | Required |
|
| The developer server endpoint URL | Yes |
|
| The request parameters | No |
|
| The request headers. The Referer header cannot be set. The default | No |
|
| The timeout duration in milliseconds | No |
|
| The HTTP request method. Default is | No |
|
| The response data format. Default is | No |
|
| The response data type. Default is | No |
|
| The callback function called when the API call succeeds | No |
|
| The callback function called when the API call fails | No |
|
| The callback function called when the API call ends, regardless of success or failure | No |
Example
TTMinis.game.request({
url: 'https://EXAMPLE_ENDPOINT',
data: {
x: '',
y: ''
},
header: {
'content-type': 'application/json'
},
success(res) {
console.log(res.data)
}
})TTMinis.game.RequestTask.abort()
Aborts the request task.
Example
const requestTask = TTMinis.game.request({
url: 'https://EXAMPLE_ENDPOINT'
})
requestTask.abort()TTMinis.game.downloadFile(opts)
Downloads a file resource to a local temporary path. The client initiates an HTTPS GET request and returns the local temporary file path.
Parameters
Field | Type | Description | Required |
|
| The URL of the resource to download | Yes |
|
| The HTTP request headers. The Referer header cannot be set. | No |
|
| The timeout duration in milliseconds. Default is 60000 (one minute). | No |
|
| The callback function called when the API call succeeds | No |
|
| The callback function called when the API call fails | No |
|
| The callback function called when the API call ends, regardless of success or failure | No |
Success callback parameters
Field | Type | Description |
|
| The temporary file path. Returned when no |
|
| The HTTP status code returned by the developer server |
Returns
A DownloadTask object that can be used to monitor and control the download.
Example
TTMinis.game.downloadFile({
url: 'https://example.com/audio/123',
success(res) {
if (res.statusCode === 200) {
TTMinis.game.playVoice({
filePath: res.tempFilePath
})
}
}
})TTMinis.game.DownloadTask.abort()
Aborts the download task.
Example
const downloadTask = TTMinis.game.downloadFile({
url: 'https://example.com/audio/123'
})
downloadTask.abort()