V
V
Vyacheslav Ryzhkov2017-08-30 22:05:26
Lua
Vyacheslav Ryzhkov, 2017-08-30 22:05:26

What is the purpose of the http.Fetch and http.Post commands?

I work here with PHP (namely with the scripts themselves), but the request itself and the result itself come from the LUA script. I'm not familiar with it, so I'm asking you a question. Help me explain exactly how these commands work: http.Fetch and http.Post . Here are code examples:

http.Fetch("http://metrostroi.net/api/mag_bans/",function(body,len,headers,code)
        metadmin.MAG = util.JSONToTable(body)
      end)
      timer.Create("MAG",5*60,0,function()
        http.Fetch("http://metrostroi.net/api/mag_bans/",function(body,len,headers,code)
          metadmin.MAG = util.JSONToTable(body)
          for k,v in pairs(metadmin.MAG) do
            local target = player.GetBySteamID(v.steamid)
            if target then
              target:Kick("MAG banned from secure server")
            end
          end
        end)
      end)

if metadmin.api_key then
      metadmin.print("Проверка АПИ ключа")
      local time = os.time()
      local hash = metadmin.sha256(GetConVar("hostport"):GetString()..tostring(time)..metadmin.api_key)
      http.Post("http://metrostroi.net/api/key_check",{port=GetConVar("hostport"):GetString(),date=tostring(time),hash=hash},
        function(body,len,headers,code)
          if body != "ok" then
            local str = "АПИ ключ не прошел проверку. ("..body..")"
            metadmin.print(str,true)
            metadmin.Log(str)
            metadmin.api_key = false
            SetGlobalBool("metadmin.partner",false)
          else
            SetGlobalBool("metadmin.partner",true)
            metadmin.print("АПИ ключ прошел проверку.")
          end
        end
      )
    end

PS In the second example, I would like to know how to "accept" requests already in PHP itself (whether there is any $_GET data or not)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SagePtr, 2017-08-30
@rugrisser

Fetch fetches data from the server and Post sends to the server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question