Namespace: http
Language: Lua
Type: Defold Lua
File: script_http.cpp
Source: engine/gamesys/src/gamesys/scripts/script_http.cpp
Functions for performing HTTP and HTTPS requests.
Type: FUNCTION Perform a HTTP/HTTPS request. If no timeout value is passed, the configuration value “network.http_timeout” is used. If that is not set, the timeout value is 0 (which blocks indefinitely).
Parameters
url (string) - target urlmethod (string) - HTTP/HTTPS method, e.g. “GET”, “PUT”, “POST” etc.callback (fun(self:script_instance, id:hash, response:http.response)) - response callback functionself:script_instanceThe current script instance</dd>
id:hashInternal message identifier. Do not use!</dd> </dl>
headers (table<string, string>) (optional) - optional table with custom headerspost_data (string) (optional) - optional data to sendoptions (http.request_options) (optional) - optional request optionsExamples
Basic HTTP-GET request. The callback receives a table with the response in the fields status, the response (the data) and headers (a table).
local function http_result(self, _, response)
if response.bytes_total ~= nil then
update_my_progress_bar(self, response.bytes_received / response.bytes_total)
else
print(response.status)
print(response.response)
pprint(response.headers)
end
end
function init(self)
http.request("http://www.google.com", "GET", http_result, nil, nil, { report_progress = true })
end
Type: STRUCT HTTP request options
Members
timeout? (number) - timeout in secondspath? (string) - absolute destination path; overwritten only for status 200ignore_cache? (boolean) - do not return cached data for status 304; unavailable on HTML5chunked_transfer? (boolean) - use chunked transfer encoding for HTTPS requests larger than 16 KB; defaults to true and is unavailable on HTML5report_progress? (boolean) - report transferred and total byte counts to the callbackType: STRUCT HTTP response data
Members
status (integer) - response statusresponse? (string) - response data when it is not saved to diskheaders? (table<string, string>) - response headers for status 200 or 206path? (string) - destination path when the response is saved to diskerror? (string) - unexpected error, such as a file I/O errorbytes_received? (integer) - bytes transferred when progress reporting is enabledbytes_total? (integer) - total request size when progress reporting is enabledrange_start? (integer) - requested-file start offsetrange_end? (integer) - requested-file end offset, inclusivedocument_size? (integer) - full requested-file size