语法
HttpGet(context: DataModel, url: string, cache?: boolean | number): string参数
| 名称 | 类型 | 描述 |
|---|---|---|
context | DataModel | Method-call self value. Use game:HttpGet(url, cache) or game:HttpGetAsync(url, cache). |
url | string | URL string to request. |
cache? | boolean | number | Optional cache control. true or numeric 1 enables the URL cache. |
返回值
| 名称 | 类型 | 描述 |
|---|---|---|
body | string | Downloaded 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)