This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| minionlib [2020/12/13 17:02] – [HTTPRequest] kali | minionlib [2021/04/30 18:13] (current) – ace | ||
|---|---|---|---|
| Line 88: | Line 88: | ||
| *Queues and Fires the Event with 1-n arguments. Eventname and arguments need to be strings. | *Queues and Fires the Event with 1-n arguments. Eventname and arguments need to be strings. | ||
| *Use RegisterEventHandler(" | *Use RegisterEventHandler(" | ||
| + | *Requires at least 1 argument, even if it's a blank string. (ex. QueueEvent(" | ||
| Line 250: | Line 251: | ||
| <code lua> | <code lua> | ||
| function SendHttpRequest() | function SendHttpRequest() | ||
| - | local API_Key = " | + | local function success(str, |
| - | local function success(str, | + | d(" |
| - | d(" | + | d(" |
| - | d(" | + | d(" |
| - | d(" | + | |
| - | local data = json.decode(str) | + | |
| - | if data then | + | if data then |
| - | d(" | + | |
| - | for _, v in pairs(data) do | + | d(data) |
| - | d(v.name) | + | end |
| - | end | + | |
| - | return | + | local function HeadersTable(header) |
| - | end | + | if type(header) == " |
| - | end | + | header = string.match(header," |
| + | local tbl = {} | ||
| + | for w in header: | ||
| + | local k,v = string.match(w," | ||
| + | | ||
| + | end | ||
| + | | ||
| + | | ||
| + | | ||
| + | end | ||
| + | |||
| + | header = HeadersTable(header) -- if you want to convert the header string to a table | ||
| + | end | ||
| - | local function failed(error, | + | local function failed(error, |
| - | d(" | + | d(" |
| - | d(" | + | d(" |
| - | d(" | + | d(" |
| - | d(str or " | + | |
| - | end | + | |
| - | local params = { | + | local params = { |
| - | host = "api.guidwars2.com", | + | host = "api.guildwars2.com", |
| - | path = "/v2/characters?ids=all& | + | path = "/v2/currencies?ids=1", |
| - | port = 443, | + | port = 443, |
| - | method = " | + | method = " |
| - | https = true, | + | https = true, |
| - | body = "", | + | onsuccess = success, |
| - | headers = "", | + | onfailure = failed, |
| - | onsuccess = success, | + | getheaders = true, --true |
| - | onfailure = failed, | + | body = "", |
| - | getheaders = true -- if true, headers | + | |
| - | } | + | |
| - | HttpRequest(params) | + | |
| + | HttpRequest(params) | ||
| end | end | ||
| </ | </ | ||