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

How do i use HTML Service ?

Asked by 8 years ago

How do i use Html service lets say a player is in a game and i am on A website and i Post some live chat to the website ( I am using Discord ) how do i make the game read that live chat and respond to it ?

0
It's almost never necessary to use this service. User#11440 120 — 8y
0
Actually this service is one of the most useful service out there. Kurieita 125 — 8y

2 answers

Log in to vote
1
Answered by
Kurieita 125
8 years ago

HttpService*

HttpService is a way to send GET and POST requests to live servers. Tho you don't need to have background knowledge in web development, it would help a whole lot.

There are 4 functions -GenerateGUID -JSONDecode -JSONEncode -UrlEncode

There are 2 functions that yield -GetAsync -PostAsync

We are only going to be talking about the functions that yield.

A GET request is pretty much a request that get the content of a web server.

For instance, if you type this in the console.

print(game.HttpService:GetAsync("https://www.example.com")

It will return the HTML of that page.

But how do I send data over? Sending data using a GetAsync is quite easy actually. The data format is in a Key/Value format and is stored in the Url.

local Data = "http://www.example.com/?var1=666&var2=1337&var=test

Now I am using PHP as the backend web server language. To access that data just simple do

<?php
$var1 = $_GET['var1']
$var2 = $_GET['var2']
$var = $_GET['var']
?>

But what about PostAsync. PostAsync post data to a web server. I highly recommend using JSON as the format for sending data to a web server. To begin I make a table that contain data I want to send to the server.

local Table = {
    ID = 1337,
    Stuff = 666
}

Next I will encode the data into JSON format

local Table = {
    ID = 1337,
    Stuff = 666
}

local Json = game.HttpService:JSONEncode(Table)

Finally I will send the data to the web server.

local Table = {
    ID = 1337,
    Stuff = 666
}

local Json = game.HttpService:JSONEncode(Table)
game.HttpService:PostAsync("http://www.example.com,  Json)

But how do I access it?

Well, PHP have a built in function called "readfile" and you use a php stream type "'php://input'"

$table = json_decode(readfile("php://input"));
echo $table['ID']; 

That will print out 1337.

Feel free to vote up. :)

Anymore questions? Just comment.

Ad
Log in to vote
0
Answered by
Xonae 0
8 years ago

Personally, I do not know much about HttpService, but I do know a few things about it. You can use :GetAsync(String url) to send a GET request to that url. I am not sure how you would go around getting live chat feedback from Discord, as I do not use it, but I wish you luck finding out!

0
Xonae do you know any of These that you are skilled in and can help in such as Irc DevDeadly3652 0 — 8y

Answer this question