This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
minionlib [2020/12/13 17:02] – [HTTPRequest] kali | minionlib [2021/01/17 20:19] – Response headers string to table example kali | ||
---|---|---|---|
Line 250: | Line 250: | ||
<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 | ||
</ | </ |