Alright so i am trying to use PostAsync from HttpService to send a post request to my php file on my website but the data i put into the second parameter of PostAsync doesn’t seem to be transfered to the $_POST var.
Here’s my code:
Roblox script preforming the Post Request:
function script.Parent.OnServerInvoke(plr, Text)
local http = game:GetService("HttpService")
local data = {
["text"] = Text
}
local response = nil
local ok, status = pcall(function()
response = http:PostAsync("http://mysite.com/requests/beta.php", http:JSONEncode(data), Enum.HttpContentType.ApplicationJson)
end)
if ok and response ~= nil then
return response
else
return "error: "..status
end
end
-- The RemoteFunction is invoked in a localscript
Please notate your code with three “grave” (`) characters before and after it. This is so code can be read with its proper indentation and character spacing, like so:
if 2 + 2 == 4 then
for i = 1, 10 do
print(i)
end
end
How it looks in the text editor:
This will allow people to have an easier time trying to help you solve your problem.
Hello instead of doing $_POST use $_GET ( not 100% sure this would work but worth the try also you should check what method Roblox uses in HttpPost $_SERVER[“REQUEST_METHOD”] )
oh also I wouldn’t recommend letting the client post as many times as it wants ( since you’re putting it in a ServerInvoke it means the client can just do Rem:InvokeServer(“hi”) and it’ll do an http request )
Exploiters could use that to their advantage and just destroy your servers easily!
Hello! I’ve been having the same issue as well lately. However, I didn’t manage
to fix it. Just switched to get instead of post. Can you post the result if you use print_r($_POST)?