SanyaRamzik

post-json opc

Jan 6th, 2021 (edited)
1,372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.97 KB | None | 0 0
  1. base_url = 'http://j99098fk.beget.tech/test/'
  2.  
  3. function parseString (inputString)
  4.  local result = {}  
  5. for value in string.gmatch(inputString, '".-":".-"') do
  6.    result[string.gsub(value, '"(.-)":"(.-)"', "%1")] = string.gsub(value, '"(.-)":"(.-)"', "%2")
  7. end
  8.  return result
  9. end
  10.  
  11. function addSlot(server,seller,slot,slot_count)
  12.     local data = 'server='..server..'&seller='..seller..'&slot='..slot..'&slot_count='..tostring(slot_count)
  13.     resp = parseString(postman(base_url,"post/addslot",data))
  14.         if(resp['key']=='false') then return false end
  15.         return resp['info']
  16. end
  17.  
  18. function postman(url,param,data)
  19.     headers = {
  20. ["content-type"] = "application/json"
  21. ,["user-agent"] = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36" }
  22. local postUrl=url..param.."?"..data
  23. local resp={}
  24. local req=internet.request(postUrl,'',headers)
  25. for line in req do table.insert(resp,line) end
  26. return resp[1] -- return json string
  27. end
Advertisement
Add Comment
Please, Sign In to add comment