generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: HttpService PostAsync()

Previous Thread :: Next Thread 
Digitalizing is not online. Digitalizing
Joined: 13 Aug 2013
Total Posts: 1057
23 Dec 2013 06:53 PM
How can I use PHP to retrieve and process what the ROBLOX server sends via PostAsync()
Report Abuse
Kenetec is not online. Kenetec
Joined: 26 Nov 2009
Total Posts: 1662
23 Dec 2013 07:03 PM
Just like you would with any other POST variable... $_POST['var_name']

Make sure you send the urlencoded string of vars via postasync with the UrlEncode method
Report Abuse
Digitalizing is not online. Digitalizing
Joined: 13 Aug 2013
Total Posts: 1057
23 Dec 2013 07:12 PM
Thanks, I thought it would be unique.
Report Abuse
Digitalizing is not online. Digitalizing
Joined: 13 Aug 2013
Total Posts: 1057
23 Dec 2013 07:29 PM
So I would run the script:

local httpService = Game:GetService("HttpService");
local url = httpService:UrlEncode("MyWebUrl/roblox/index.php")
PostAsync (url, "$rbxVar='lel roblux'", application/x-www-form-urlencoded)

and the PHP:

?php
$_POST['rbxVar'];

or do I not understand?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Dec 2013 08:57 PM
no, you did it pretty wrong.
Report Abuse
Digitalizing is not online. Digitalizing
Joined: 13 Aug 2013
Total Posts: 1057
23 Dec 2013 09:09 PM
expected that.
Report Abuse
Digitalizing is not online. Digitalizing
Joined: 13 Aug 2013
Total Posts: 1057
23 Dec 2013 10:31 PM
what did I do wrong though, is the thing.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Dec 2013 10:32 PM
the PHP is completely wrong and so is this:
PostAsync (url, "$rbxVar='lel roblux'", application/x-www-form-urlencoded)
Report Abuse
Digitalizing is not online. Digitalizing
Joined: 13 Aug 2013
Total Posts: 1057
23 Dec 2013 10:50 PM
well *what* is wrong
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
23 Dec 2013 11:05 PM
local httpService = Game:GetService("HttpService");
local url = "http://www.example.org/roblox/index.php"
local body = "rbxVar=" .. httpService:UrlEncode("lel roblux")
httpService:PostAsync(url, body, Enum.HttpContentType.ApplicationUrlEncoded)

And you basically got the PHP right, you just need to do something with the value:

echo $_POST['rbxVar'];
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Dec 2013 11:08 PM
He forgot the " < " in ?php and the " > " to close it
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
23 Dec 2013 11:11 PM
I intentionally omitted the tags because I thought the filter might reject my post if I included them.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Dec 2013 11:12 PM
oh
Report Abuse
OneTrueGodTheHolyCow is not online. OneTrueGodTheHolyCow
Joined: 24 Oct 2013
Total Posts: 9350
24 Dec 2013 07:27 AM
HTTP tutorial pls someone and u have my <3 forevar
Report Abuse
Digitalizing is not online. Digitalizing
Joined: 13 Aug 2013
Total Posts: 1057
24 Dec 2013 07:47 AM
How exactly am I supposed to translate lua into php when encoding it?
local body = "rbxVar=" .. httpService:UrlEncode("lel roblux")
Report Abuse
Digitalizing is not online. Digitalizing
Joined: 13 Aug 2013
Total Posts: 1057
24 Dec 2013 08:06 AM
I'm new to back-end web development, I usually make otherwise.
Report Abuse
MettaurSp is not online. MettaurSp
Joined: 20 Mar 2010
Total Posts: 3179
24 Dec 2013 09:45 AM
I just learned GET so I wouldn't have to learn anything else when making the PHP file.
Report Abuse
Digitalizing is not online. Digitalizing
Joined: 13 Aug 2013
Total Posts: 1057
24 Dec 2013 03:05 PM
I put in the necessary PHP for when a user steps on a block, it puts the user's ID and username into a database. I just need to know how to translate PHP to Lua for 'body = '.
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
24 Dec 2013 04:32 PM
Okay, so your PHP script is expecting the request body to be in this format:

key=value&key2=value2

So it's a semicolon-separated list of key-value pairs. However, you should always URL encode keys and values because they might contain characters like '&' or '=' and that might mess things up. Here is a function which will do it for you:

local HttpService = Game:GetService("HttpService")

function url_encode(form)
local result = {}
for key, value in pairs(form) do
table.insert(result, HttpService:UrlEncode(key) .. "=" .. HttpService:UrlEncode(value))
end
return table.concat(result, "&")
end

And you would use it like this:

local url = "http://www.example.org/roblox/index.php"
local body = url_encode({ userId = 261, userName = Shedletsky })

HttpService:PostAsync(url, body, Enum.HttpContentType.ApplicationUrlEncoded)
Report Abuse
Digitalizing is not online. Digitalizing
Joined: 13 Aug 2013
Total Posts: 1057
24 Dec 2013 05:11 PM
So this script would work:
local httpService = Game:GetService("HttpService");
url = "myurl";
local block = script.Parent;
function detectBlockStep(hit)
local h = hit.Parent:findFirstChild("Humanoid");
if h ~= nil then
char = h.Parent;
username = char.Name
userID = char.GetPlayerFromCharacter().userId
local body = url_encode({ userID, username });
end
end
block.Touched:connect(detectBlockStep);

with:
$con=mysqli_connect("myurl","dbuser","dbuserpass","dbname");
$userID = $_POST['userID'];
$username = $_POST['username'];
mysqli_query($con,"INSERT INTO rbxBrick (userID, username) VALUES ($userID, $username)");
mysqli_close($con);
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Dec 2013 06:48 PM
Guise injecting time
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
24 Dec 2013 09:13 PM
instead of:
char.GetPlayerFromCharacter()
do:
Game.Players:GetPlayerFromCharacter(char)

and instead of:
url_encode({ userID, username });
do
url_encode({ userId = userID, username = username });
Report Abuse
jackendra is not online. jackendra
Joined: 20 Mar 2011
Total Posts: 66
07 Feb 2014 02:13 PM
I still cant get it too work.

I tried tons of Lua code and PHP code.

Maybe its my web host?

Report Abuse
jackendra is not online. jackendra
Joined: 20 Mar 2011
Total Posts: 66
07 Feb 2014 02:16 PM
Php:
$fp = fopen('data.txt', 'w');
fwrite($fp, $_POST['var']);
fwrite($fp, $_GET['var']);
fclose($fp);

Lua:

local httpService = Game:GetService("HttpService");
url = "http://roscript.site88.net/http.php";
local body = "var=" .. httpService:UrlEncode("roblox");
httpService:GetAsync(url, body, Enum.HttpContentType.TextPlain); -- Also tried Enum.HttpContentType.ApplicationUrlEncoded
Report Abuse
Kenetec is not online. Kenetec
Joined: 26 Nov 2009
Total Posts: 1662
07 Feb 2014 02:21 PM
You're using getasync, not postasync
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image