Miscellaneous

HttpGet

Performs a GET request for game:HttpGet(url, cache) or game:HttpGetAsync(url, cache) and returns the response body string.

语法

HttpGet(context: DataModel, url: string, cache?: boolean | number): string

参数

名称类型描述
contextDataModelMethod-call self value. Use game:HttpGet(url, cache) or game:HttpGetAsync(url, cache).
urlstringURL string to request.
cache?boolean | numberOptional cache control. true or numeric 1 enables the URL cache.

返回值

名称类型描述
bodystringDownloaded response body string, cached body string, or an empty string when the request cannot be opened.

说明

Performs a GET request for game:HttpGet(url, cache) or game:HttpGetAsync(url, cache) and returns the response body string. The URL must pass Real's URL restrictions.

使用 3 个参数调用: context, url, cache。参数表会说明哪些值必填,哪些值只用于细化行为。

返回 body (string)。使用返回表区分成功值、nil 结果和可恢复错误。

示例

Run a DataModel-style GET request and return the response body string.

local body = game:HttpGet("https://example.com", true)
print(body)