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 » Scripting Helpers
Home Search
 

Re: Http Service...

Previous Thread :: Next Thread 
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
18 Dec 2013 05:23 PM
I am just trying to get Http service to work but I am not quite sure how to handle the Post request on the PHP side.
Report Abuse
StBashkir is not online. StBashkir
Joined: 29 Aug 2008
Total Posts: 26171
18 Dec 2013 05:26 PM
I, personally, haven't used the ROBLOX HttpService, but how are you currently handling the data sent to your server php script?

I would think that you would access the incoming JSON data through first grabbing the post index.

$JSON = $_POST['incoming_header'];
// then
$array = json_decode($JSON);
Report Abuse
StBashkir is not online. StBashkir
Joined: 29 Aug 2008
Total Posts: 26171
18 Dec 2013 05:27 PM
My bad.

Have you tried using

print_r($_POST);

To see if the post header contains anything?
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
18 Dec 2013 05:30 PM
Just an empty array...
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
18 Dec 2013 05:45 PM
You will have to put the variables in the url and use php $_GET['VariableName'] to get it's value..

i.e.:

blahblah/handle.php?Variable=Value&AnotherVariable=AnotherValue
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
18 Dec 2013 05:48 PM
Can'y you use POST and not put the variables in the URL?...I though that was the difference inbetween POST and GET.
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
18 Dec 2013 06:36 PM
POST is when they send data in that's filled out in a form, it's method is different than when you url encode the variables, which is when you use GET.. ROBLOX doesn't support POST [so far as I know] yet so you will have to use GET and url encoding if you want to send variables to a php script..
Report Abuse
StBashkir is not online. StBashkir
Joined: 29 Aug 2008
Total Posts: 26171
18 Dec 2013 06:40 PM
Yeah, I can't seem to get the POST request to actually post anything to my site either...no matter the data format or the HttpContentType
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
18 Dec 2013 06:43 PM
I don't know anything other than :PostAsync(url).. I'm kinda curious where everyone is getting these other functions from the HttpService..
Report Abuse
StBashkir is not online. StBashkir
Joined: 29 Aug 2008
Total Posts: 26171
18 Dec 2013 06:45 PM
^^^

http://wiki.roblox.com/index.php/RBX.lua.HttpService_(Object)
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
18 Dec 2013 06:49 PM
Ah, Seems the POST must use a JSON encoded string as the second variable.. or xml or whatever else if you'd rather, just have to change the format in the third variable..
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
18 Dec 2013 06:50 PM
I diid change the datatype to plain text...
Report Abuse
StBashkir is not online. StBashkir
Joined: 29 Aug 2008
Total Posts: 26171
18 Dec 2013 06:51 PM
"Ah, Seems the POST must use a JSON encoded string as the second variable.. or xml or whatever else if you'd rather, just have to change the format in the third variable.."

local s = Game:GetService("HttpService")
local vals = {1,2,3};
vals = s:JSONEncode(vals);
local r = s:PostAsync("MySite/_roblox.php", vals,0);
print(r); print(vals);

No matter the encoding, it doesn't seem to return anything but an empty array when the php script is to return via print_r();
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
18 Dec 2013 07:04 PM
I just built a small test system, the test succeded.. I got all of the data I POSTed to my site via :PostAsync(site/file.php,'JSONHERE')...

Also, I'ma be updating my Cross-Server chat system to use this method now as when I made it I only knew of the GetAsync function xD
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
18 Dec 2013 07:09 PM
Typo: site/file.php was made into a string using 'site/file.php'
Report Abuse
StBashkir is not online. StBashkir
Joined: 29 Aug 2008
Total Posts: 26171
18 Dec 2013 07:12 PM
@Christbru01

Can you give an example of the way you are encoding your JSON? What is being encoded, and how you are _sure_ you are receiving the POST data on your site (php code preferably)?
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
18 Dec 2013 07:20 PM
Server-Side PHP Code:

$foo = file_get_contents("php://input");
$stuff = json_decode($foo, true);

if(isset($stuff['test'])){
echo $stuff['test'];
} else {
echo 'Not found';
}

Lua Request:

print(game:GetService("HttpService"):PostAsync("site/testcall.php",'{"test":"Works"}'))

Returned:

Works
Report Abuse
StBashkir is not online. StBashkir
Joined: 29 Aug 2008
Total Posts: 26171
18 Dec 2013 07:30 PM
@Christbru01

Thank you. I didn't even know I should be using the raw post data for this (php://input). Once I switched over to that from $_POST[], the data started showing up.
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
18 Dec 2013 08:22 PM
Yeah, it's not quite posted as a usual browser would, so you have to get the raw data yourself..

On another note, I've finished updating my cross-server chat to work with Post instead of Get c:
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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