21.08.2018, 12:06
Code:
http = require('socket.http')
ltn12 = require('ltn12')
json = require('json')
function dorequest(url, headers, data)
local resp = {}
headers['Content-Length'] = #data
local res, err = http.request({
url = url,
method = 'POST',
headers = headers,
sink = ltn12.sink.table(resp),
source = ltn12.source.string(data)
})
if res then
return table.concat(resp)
else
return nil, err
end
end
url = 'http://api.kairos.com/detect'
imageurl = 'http://...'
app_id = 'YOUR_APP_ID'
app_key = 'YOUR_APP_KEY'
headers = {
['Content-Type'] = 'application/json',
['app_id'] = app_id,
['app_key'] = app_key,
}
data = json.encode({
['image'] = imageurl
})
res, err = dorequest(url, headers, data)
log(res, err)