The native in question: PERFORM_HTTP_REQUEST_INTERNAL
I’ve had a multitude of bugs using this native. I don’t know if I’m just really bad at PHP or if this is internal bugs. They are consistent bugs that happen all of the time, no matter the situation.
#1
“METHOD” parameter not working
Simple explanation: No matter the method I use such as “POST” “HEAD” or “GET”, they all seems to be received as “GET” by the php server.
#2
Legacy “DATA” not sending
I could just be bad at PHP with this one (only tested with “GET” because of above bug), but whenever I send data through the native (I know it’s legacy one=1&two=2
) it seems to always not be recieved.
I use
$x = $_GET["one"]
but $x
always seems to be null.
Here is the code I use for the native (basically stolen from scheduler.lua
):
local current = {}
AddEventHandler('__cfx_internal:httpResponse', function(token, status, body, headers)
if current[tostring(token)] then
local cb = current[tostring(token)]
current[tostring(token)] = nil
cb({status, body, headers})
end
end)
function httpRequest(args)
local t = {
url = args[1],
method = args[2],
data = args[3],
headers = args[4]
}
local d = json.encode(t)
local token = PerformHttpRequestInternal(d, d:len())
current[tostring(token)] = args[5]
end