☁️network
发送异步网络请求。
Functions:
http
network.http(url: string[, params: table]): Future
url
string
network.http("https://www.baidu.com/", {
method = "post", -- 允许 get/post/put/delete 方法
headers = {
["test-header"] = "1",
h2 = 2,
-- ["content-type"] = "application/json" -- 手动设置content-type
},
-- body = "test-body",
body = json.stringify({
test = 1
})
}):and_then(function(res)
print(res.status)
print(res.body)
for k, v in pairs(res.headers) do
print(k, v)
end
end):map_err(function(err)
print(err)
end)http(s)请求。
proxy
network.proxy(url: string[, timeout: number]): Proxy
url
string
socks4|socks5|http
timeout
number
超时(毫秒)
代理客户端,继承所有network方法(除了自身和http_client)。
socket
network.socket(url: string[, timeout: number]): Future
url
string
timeout
number
超时(毫秒)
socket tcp客户端。
tls_socket
network.tls_socket(url: string[, skip_verify: bool, timeout: number]): Future
tls socket tcp客户端。
http_client
network.http_client([proxy: string, timeout: number]): HttpClient
创建一个干净的http客户端。
websocket
network.websocket(url: string [, timeout: number]): Future
url
string
timeout
number
超时(毫秒)
websocket客户端。
Structs:
🔗 HttpClient
HttpClient:request
client:request(url: string[, params: table]): Future
🔗 HttpOptions
HttpOptionsmethod
string|nil
headers
table|nil
body
string|nil
timeout
number|nil
🔗 SocketStream
SocketStream:read
socket:read(size: number): Future
size
number
读取长度
读取原始回复。
:write
ws:write(content: string): Future
content
string
发送内容
写入数据。
:close
socket:close()
关闭连接。
:write_all
ws:write_all(content: string): Future
content
string
发送内容
写入所有数据。
:read_to_string
socket:read_to_string(size: number): Future
size
number
读取长度
读取字符串回复。
🔗 WebSocketStream
WebSocketStream:read
ws:read(): Future
读取回复。
:write
socket:write(content: string, packet: e_WSmsgType): Future
content
string
发送内容
写入数据。
:close
ws:close()
关闭连接。
:listen
socket:listen(callback: function)
callback
function
Enumerates:
🔗 WSmsgType
WSmsgType0
text
1
binary
2
ping
3
pong
4
close
5
frame
最后更新于