Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

PostAsync not seeming to work?

Asked by 7 years ago

I'm trying to post some data to a site, and if there is data it'll echo "posted", if not it'll echo "not posted". However, when using this, I try to post data to the site and it always does "not posted".

Here's my php code: if (!empty($_POST)){ echo'posted' } else { echo'not posted'}

Here's my lua code: print(game:GetService("HttpService"):PostAsync("http://local??host/tutorial/index.??php","test"))

Thanks so much!

0
Use code blocks for code. And what are you even doing exactly? TheDeadlyPanther 2460 — 7y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
7 years ago
Edited 7 years ago

AFAIK, the $_POST variable in PHP is only used for form encoded post values (i.e., a format used by HTML forms, and not by your code here)

Use $postdata = file_get_contents("php://input"); to get the full contents of the posted message.

0
Thank you, this works. However, let's say I post a table. When I try to index the table from PHP it just returns the index of the string. How would I get an index from a table which was posted, rather than a string? NewVoids 97 — 7y
0
...you can't, PHP isn't Lua, there are no tables. You have to parse it. Most likely serialize as JSON at the Lua and and parse as JSON in the PHP end. BlueTaslem 18071 — 7y
Ad

Answer this question