🌐 HTTP
HTTP 请求接口。
🗿Static Class
This is a Static Class. Access it's methods directly with
.. It's not possible to spawn new instances.🧑💻API Source
This page is auto-generated! The Functions, Properties and Events described here are defined in our GitHub's API Repository! Feel free to commit suggestions and changes to the source .json API files!
🎒 示例
(HTTP.Request) Makes an asynchronous HTTP Request
local ret = HTTP.Request("127.0.0.1:7777", "/", HTTPMethod.GET, "", "application/json", false, {})
Console.Log(ret.Status) -- 200
Console.Log(ret.Data) -- "{"players_count":0,"server_name":"nanos world server"}"
(HTTP.RequestAsync) Makes an asynchronous HTTP Request
HTTP.RequestAsync("127.0.0.1:7777", "/", HTTPMethod.GET, "", "application/json", false, {}, function(status, data)
Console.Log(status) -- 200
Console.Log(data) -- "{"players_count":0,"server_name":"nanos world server"}"
-- TIP: You can parse it if it's a json return as well
local json_ret = JSON.parse(data)
end)
提示
All requests are thread safe! 🥳 这意味着回调函数在主线程上返回了!
🗿 静态函数
| Returns | Name | Description | |
|---|---|---|---|
| table | Request | 发起同步 HTTP 请求 | |
RequestAsync | 发起异步 HTTP 请求 | ||
SetConnectionTimeout | 设置 HTTP 请求的全局连接超时时间(秒) | ||
SetReadWriteTimeout | 设置 HTTP 请求的全局读写超时时间(秒) |

Request
Makes a synchronous HTTP Request.
The request will be made synchronously and will freeze the server until it's done.
local ret = HTTP.Request(uri, endpoint?, method?, data?, content_type?, compress?, headers?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | uri | Required parameter | 主 URI(基本地址) |
| string | endpoint? | | 终点 |
| HTTPMethod | method? | HTTPMethod.GET | 要使用的 HTTP 方法 |
| string | data? | | 有效载荷 |
| string | content_type? | application/json | 要使用的内容类型 |
| boolean | compress? | false | 是否使用 gzip 压缩内容 |
| table | headers? | {} | 要使用的标头 |
Returns
| Type | Description |
|---|---|
| table | with this format |
HTTP.Request Examples
Makes an asynchronous HTTP Request
local ret = HTTP.Request("127.0.0.1:7777", "/", HTTPMethod.GET, "", "application/json", false, {})
Console.Log(ret.Status) -- 200
Console.Log(ret.Data) -- "{"players_count":0,"server_name":"nanos world server"}"

RequestAsync
发起异步 HTTP 请求。
该请求将异步发出,并在完成后在所提供的回调函数中安全地在相同线程内返回。
注:如果在卸载包时请求仍在运行,服务器将冻结直到请求完成,随后包才会卸载。
HTTP.RequestAsync(uri, endpoint?, method?, data?, content_type?, compress?, headers?, callback?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | uri | Required parameter | 主 URI(基本地址) |
| string | endpoint? | | 终点 |
| HTTPMethod | method? | HTTPMethod.GET | 要使用的 HTTP 方法 |
| string | data? | | 有效载荷 |
| string | content_type? | application/json | 要使用的内容类型 |
| boolean | compress? | false | 是否使用 gzip 压缩内容 |
| table | headers? | {} | 要使用的标头 |
| function | callback? | nil | 结果 with this format |
HTTP.RequestAsync Examples
Makes an asynchronous HTTP Request
HTTP.RequestAsync("127.0.0.1:7777", "/", HTTPMethod.GET, "", "application/json", false, {}, function(status, data)
Console.Log(status) -- 200
Console.Log(data) -- "{"players_count":0,"server_name":"nanos world server"}"
-- TIP: You can parse it if it's a json return as well
local json_ret = JSON.parse(data)
end)

SetConnectionTimeout
设置 HTTP 请求的全局连接超时时间(秒)
HTTP.SetConnectionTimeout(connection_timeout)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | connection_timeout | Required parameter | 超时时间(秒) |

SetReadWriteTimeout
设置 HTTP 请求的全局读写超时时间(秒)
HTTP.SetReadWriteTimeout(read_write_timeout)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | read_write_timeout | Required parameter | 超时时间(秒) |
🚀 事件
This class doesn't have own events.