xhookLua
Game

network

Async HTTP and HTTPS via the system proxy; callbacks run on the main thread, 16 requests at once.

Functions

network.get

network.get(url, callback [, headers])
NameTypeDescription
urlstringhttp:// or https:// only.
callbackfunctioncallback(ok, status, body, headers, err).
headersoptionaltable{ ["Name"] = "value" }. Default none.

Sends a GET with a 15 second timeout.

  • Raises for a non-http(s) URL.
  • The callback is dropped if its script reloads first.

network.post

network.post(url, body, callback [, content_type = "application/json" [, headers]])
NameTypeDescription
urlstringhttp:// or https:// only.
bodystringBinary-safe.
callbackfunctioncallback(ok, status, body, headers, err).
content_typeoptionalstringDefault "application/json".
headersoptionaltable{ ["Name"] = "value" }. Default none.

Sends a POST with a 15 second timeout.

  • Raises for a non-http(s) URL.
  • To pass headers, give content_type (or nil) first.

network.request

network.request(options, callback)
NameTypeDescription
optionstable{ url, method, body, headers, timeout }.
callbackfunctioncallback(ok, status, body, headers, err).

Sends any method; timeout clamps to 1 to 120 seconds.

  • Raises on a non-http(s) url or lower-case method.
  • Adds no Content-Type; a non-string body is sent empty.

Fields

network callback(ok, status, body, headers, err) arguments

NameTypeDescription
okbooleantrue for any response, even 404.
statusintegerHTTP code; 0 if no response.
bodystringBinary-safe, cut off at 16 MB.
headerstableLower-cased names; repeats keep the last.
errstring|nilnil on success, else an error string.
network ยท Lua API ยท xhook