local function login(Credentials)
-- url-encoded POST parameters
local _, _, header = net.http.post{
url = '127.0.0.1:7654/session/login',
parameters = Credentials,
live = true
}
-- return only the set cookie from header
return header["Set-Cookie"]:split(';')[1]
end
local function logout(Cookie)
net.http.post{
url = '127.0.0.1:7654/session/logout',
headers = {['Cookie'] = Cookie},
live = true
}
end
function main()
local credentials = {
username='admin',
password='password'
}
-- Log in and get a session cookie
local cookie = login(credentials)
-- Call an Iguana X apiAPI using the cookie
local componentList = net.http.post{
url = '127.0.0.1:7654/component/list',
headers = {['Cookie'] = cookie},
live = true
}
local componentList = json.parse{data=componentList}
-- Make more API calls with the cookie
-- Log logoutout
logout(cookie)
end |