主题
HttpService
状态同步编辑器中用于访问云平台接口的服务,承担创建云平台接口客户端的职责。它提供创建客户端的能力,允许在创建时传入可选的密钥文本与配置表,从而得到可复用的云平台接口客户端实例。
概览
状态同步编辑器中用于访问云平台接口的服务,承担创建云平台接口客户端的职责。它提供创建客户端的能力,允许在创建时传入可选的密钥文本与配置表,从而得到可复用的云平台接口客户端实例。
Get by:
lua
-- @runtime editor
local service = editor:GetService("HttpService")函数
CreateCloudAPIClient
创建云平台 API 客户端。该函数属于 HttpService,接收可选的 apiKey 与 options 参数,并返回一个新的 CloudAPIClient 实例,供后续访问云平台接口使用。
参数
| 参数 | 类型 | 说明 |
|---|---|---|
apiKey | String | 请求使用的 API Key,未设置时不添加 X-Api-Key 请求头。 |
options | Table | 支持 timeout (Number,可选):实例默认超时值,须为正数,默认 10;单次请求的 options.timeout 可覆盖该默认值。 |
返回值
| 类型 | 说明 |
|---|---|
CloudAPIClient | 新创建的云平台 API 客户端实例。 |
调用 CreateCloudAPIClient
lua
-- @runtime editor
local httpService = editor:GetService("HttpService")
local apiKey = "attack" -- String
local options = {} -- Table
local result = httpService:CreateCloudAPIClient(apiKey, options) -- 返回 CloudAPIClient
if result ~= nil then
print("调用成功,结果: " .. tostring(result))
end