I’m trying to send some data to a json file that gets added to a diffrent DB so we can use this data on our website. But i keep getting the error "Attempt to call a nil value {global ‘PerformHTTPRequest’}
The code is below:
RegisterCommand('112', function(source, args, raw)
local url = "http://ip/url/filename.json"
local args = table.concat(args, ' ') -- Group up all the info that is send with the exceutedcommand.
-- Get location of call
local x,y,z = table.unpack(GetEntityCoords(PlayerPedId()))
local streetname = exports[GetCurrentResourceName()]:reverseStreetHash(GetStreetNameAtCoord(x,y,z))
local zone = exports[GetCurrentResourceName()]:reverseZoneHash(GetHashKey(GetNameOfZone(x, y, z)))
local area = exports[GetCurrentResourceName()]:reverseAreaHash(GetHashOfMapAreaAtCoords(x, y, z))
local locationString = string.format("%s, %s (%s)", streetname, zone, area)
PerformHttpRequest(url, function(err, text, header) end,
'POST',
json.encode({username = source, content = args, location = locationString}), {["Content-Type"] = 'application/json'})
end, false)
-- Returns the error SCRIPT ERROR: @resourcename/client/client.lua 161 (this script) "Attempt to call a nil value {global 'PerformHTTPRequest'}
So a player uses /112 “Help my dog is drowning”. “Help my dog is drowning” is the new args and get sent to the HTTPRequest. But that isn’t working cause of the error.
Unfortunately, I don’t have much knowledge on this point…
You can start by checking that the server response is equal to 200
After decode response and print
something like this
PerformHttpRequest(url, function(status, text, header)
if status == 200 then
print(json.decode(text)
end
end, 'POST', json.encode({username = name, meldingsbericht = args, postcode = locationString, statusmelding = "open"}), {["Content-Type"] = 'application/json'})