|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 18 Dec 2013 06:50 PM |
| I diid change the datatype to plain text... |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
|
| 18 Dec 2013 07:09 PM |
| Typo: site/file.php was made into a string using 'site/file.php' |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|