Riferimento API di nanos world Documentazione italiana non ufficiale
Documentazione ufficiale
Funzione statica Condiviso Veloce

HTTP.RequestAsync

Makes an asynchronous HTTP Request.<br/><br/>The request will be made asynchronously and returned safely in the same thread in the callback provided when it's done.<br/><br/><b>Note:</b> If a request is still running when unloading packages, the server will freeze until it's finished, then the package will unload.

Non ancora tradotto

Sintassi

Lua
HTTP.RequestAsync(uri, endpoint = "", method = HTTPMethod.GET, data = "", content_type = application/json, compress = false, headers = {}, callback = nil)

Parametri

Nome Tipo Predefinito Descrizione
uri string — The main URI (the base address)
endpoint facoltativo string "" The endpoint
method facoltativo HTTPMethod HTTPMethod.GET The HTTP Method to be used
data facoltativo string "" Payload
content_type facoltativo string application/json The <a href='https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types'>Content Type</a> to be used
compress facoltativo boolean false Whether or not to compress the content with gzip
headers facoltativo table {} The <a href='https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers'>Headers</a> to be used
callback facoltativo function nil The result
Firma della callback function(status, data, headers)

Esempi

Makes an asynchronous HTTP Request
HTTP.RequestAsync("127.0.0.1:7777", "/", HTTPMethod.GET, "", "application/json", false, {}, function(status, data, headers),    Console.Log(status) -- 200,    Console.Log(data) -- "{"players_count":0,"server_name":"nanos world server"}",    Console.Log(headers["Content-Type"]) -- "application/json",,    -- TIP: You can parse it if it's a json return as well,    local json_ret = JSON.parse(data),end)